Dayzza
Dayzza

Reputation: 1557

preg replace for whitespace to be used in html format

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

Upvotes: 0

Views: 129

Answers (1)

Molecular Man
Molecular Man

Reputation: 22386

Do you know what <br> is doing?

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

Upvotes: 1

Related Questions