0

I am trying to replace a certain word in php and include a whitespace in it.

This string will eventually be encode as html format. However, after encoding in html format, &nbsp always turns up to be a 'newline' instead of 'one standard space'. May i know why is that so? Thanks

$storeAddr = preg_replace('/test/', "<br>&nbsp;test1", $storeAddr); 

I.E
    string: 1)xxxxtestxxxx
    current output: 1)xxx

                    testxxxx

    desired output: 1)xxx
                      testxxxx
0

1 Answer 1

1

Do you know what <br> is doing?

It inserts line break. So in your code <br> turns up to be a 'newline'.

Sign up to request clarification or add additional context in comments.

6 Comments

yea i know.. so including my <br> & &nbsp...i end up having two new line instead of one newline and one blank space infront of "test1"
@Jonathan, is preg_replace the only function that you use for strings formatting? Don't you use anything like nl2br?
only using preg_replace ... using it to replace certain word and in additional adding a space infront of the word for formatting purposes. n12br does not help me in this situation..
So, @Jonathan, after performing all manipulations on your string you should get such string: 1)xxxx<br>&nbsp;test1xxxx. In jsfiddle it works as expected.
yeah thats why i am also trying to find out why.. anyway thanks for your help so far.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.