Stripping HTML by PHP

Discussion in 'PHP' started by Scorpiono, Jul 23, 2008.

  1. #1
    Hello, kindly tell me why this is not working, I'm a begginer in PHP.

    <?php
    
    $a = file_get_contents("http://www.manele.me/");
    ereg_replace("<", "&lt;", $a);
    ereg_replace(">", "&gt;", $a);
    echo $a;
    
    ?>
    Code (markup):

     
    Scorpiono, Jul 23, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    ereg_replace returns the new value, and you have to assign it to a variable. ($a)
     
    nico_swd, Jul 23, 2008 IP
  3. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Oh okay, thanks evil monkey, I'll try!
     
    Scorpiono, Jul 23, 2008 IP
  4. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Do you want to strip ALL html tags or just convert the '<' into '&lt;' and '>' to '&gt;' ?
    If you want to strip ALL html tags, use strip_tags() functions.
    Else have a look at htmlentities() and htmlspecialchars() functions.
     
    rohan_shenoy, Jul 23, 2008 IP
  5. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Thank you.

    I want to grab every link from a page, I'd have to learn more about preg_match? or?
     
    Scorpiono, Jul 23, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    nico_swd, Jul 23, 2008 IP
    Scorpiono likes this.
  7. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Thanks, lovely reference website.
     
    Scorpiono, Jul 23, 2008 IP
  8. BDazzler

    BDazzler Peon

    Messages:
    215
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Is that all you want to do? Because if you want, you can just use htmlentities. The following is from the PHP manual ..


    
    <?php
    $str = "A 'quote' is <b>bold</b>";
    
    // Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str);
    
    // Outputs: A &# 039 ;quote &# 039 ; is &lt;b&gt;bold&lt;/b&gt;
    echo htmlentities($str, ENT_QUOTES);
    ?> 
    
    PHP:

    BTW ... I had to put the spaces in between the # and the 39 so it wouldn't get translated to '
     
    BDazzler, Jul 23, 2008 IP