SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member drennen's Avatar
    Join Date
    Nov 2003
    Location
    belgium
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with newer PHP version

    What it says in the MySql database field:

    <p>text</p>
    <p>text</p>

    So when I load it into a variable $content and write the variable using html_entity_decode($content) it will echo as:

    <p>text</p>
    <p>text</p>

    What i need it to output is:

    <p>text</p><p>text</p>

    so i can assign a Javascript variable to it.

    It used to work like this in PHP4:

    <script>
    var bodyTag='<style>body {font-family: Arial;}</style><body>'
    <?
    $content = html_entity_decode($content);
    $content = str_replace(">
    <",">';\nbodyTag+='<",$content); // written over 2 lines
    echo "bodyTag+='".$content."';\n";
    ?>
    </script>

    But in a newer PHP version it doesn't seem to accept this line of code anymore. Notice I had to write the piece of code over two lines to remove the new line.

    I've tried using the chr() function to replace it but none of the ascii codes seem to be working.

    Anyone have a suggestion, or better yet, a solution?

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Want to get rid of the newlines? (Note the use of double-quotes with the new line)
    PHP Code:
    str_replace("\n"''$string); 

  3. #3
    SitePoint Member drennen's Avatar
    Join Date
    Nov 2003
    Location
    belgium
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know, but it wasn't enough: this is my current solution. It works but it seems crude:
    Code:
    var bodyTag='<style>body {font-family: Arial;}</style><body>';
    
    <?
    $content = html_entity_decode($content);
     
    $lt = strpos($content,">")+1;
    $gt = strpos($content,"<",$lt);
    $slash = strpos($content,"/",$gt)-$gt-1;
     
    while ($gt-$lt) {
    
     if ($slash > 0) {
      $content = substr_replace($content,'',$lt,$gt-$lt);
     }
     
     $lt = strpos($content,">",$lt)+1;
     $gt = strpos($content,"<",$lt);
     $slash = strpos($content,"/",$gt)-$gt-1;
    
    }
    
    $content = str_replace("\n", '', $content);
    $content = str_replace("\r", '', $content);
     
    $content = str_replace("><",">';\nbodyTag+='<",$content);
    
    echo "bodyTag+='".$content."';\n";
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •