Hi all, i am still learning php really and the project i am working on is to help me learn, i am just wondering if anyone has a good example or tutorial of parsing urls?
Well i now have this system; //urls $chr_limit = '45'; $add = '...'; $post_body['body'] = preg_replace("!(http:/{2}[\w\.]{2,}[/\w\-\.\?\&\=\#]*)!e", "'<a href=\"\\1\" title=\"\\1\" target=\"_blank\">'.(strlen('\\1')>=$chr_limit ? substr('\\1',0,$chr_limit).'$add':'\\1').'</a>'", $post_body['body']); PHP: Only thing i need now is one to pick up urls without a http:// before them any ideas to possibly modify this one?
why do you want to design your system using BBCODE? to limit it more? It give users more hassle, IMO.
regular expression for a valid url: preg_match('/^http\:\/\/(www\.)?([a-z0-9][a-z0-9-]+\.)+[a-z]{2,4}\/?$/', $url)
Well put it this way lappy...if users can use html they can do all kinds of crazy things...there has to be a point that i stop them. Thanks stanislav ill give that a go!
I don't actually get how to use preg_match, isn't preg match just for finding? I'm trying to replace...