Remove links with PHP

Discussion in 'PHP' started by adacprogramming, Nov 28, 2008.

  1. #1
    mysql_query("INSERT INTO review(`carid`,`reviewer`,`site`,`review`)VALUES('$_POST[id]','$_POST[reviewer]','$_POST[site]','$rev')") or die(mysql_error());
    
    Code (markup):
    How would I write the PHP to delete out any links that someone tires to add to a review that they post?

    This is the insert string I'm using. The parameter is $rev
    I would imagine it will be a "replace" function where I look for anything that looks like a link and replace it with a space.

    As an alternative can I look for a link, if someone adds one then I can assume they are a spammer and abort the insert.


    Also, how would you add rel="nofollow" to the link in the "site" parameter, first checking to be sure a link is added.

    Thanks
     
    adacprogramming, Nov 28, 2008 IP
  2. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #2
    you can try this
    $rev= preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '', $_POST['rev']);
    PHP:
     
    misbah, Nov 28, 2008 IP
    adacprogramming likes this.
  3. adacprogramming

    adacprogramming Well-Known Member

    Messages:
    1,615
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Great, I'll give it a try
    Thanks
     
    adacprogramming, Nov 28, 2008 IP