Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

PHP PHP str_replace function problem

  1. Mar 20, 2010 #1
    I have this PHP code to edit all HTML text to be displayed so that it wont appear as HTML but as standard text.

    <?php
    function htmlformat($sinput){

    $newphrase = str_replace("<", "&lt;", $sinput);
    $newphrase = str_replace(">", "&gt;", $newphrase);
    $newphrase = str_replace(chr(13),"<br>",$newphrase);
    $newphrase = str_replace(chr(34), "&quot;", $newphrase);
    $newphrase = str_replace(chr(32), "&nbsp;",$newphrase);


    $newphrase=str_replace("","<font color=red>",$newphrase);

    $newphrase=str_replace("
    ","</font>",$newphrase);

    $newphrase=str_replace("","<img src=",$newphrase);

    $newphrase=str_replace("",">",$newphrase);


    return $newphrase;
    }
    ?>


    the problem is this part of the code

    $newphrase = str_replace(chr(32), "&nbsp;",$newphrase);


    it only replace the single spaces with &nbsp;
    but what about multiple spaces?
    when I have 2 more spaces on the text it cant seem to replace it with &nbsp;
     
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted