Hi how do i change a uesr input like check out: www.example.com into a link and still keep all the texts unchanged?
<?php function replace_urls_with_links( $text ) { return preg_replace( '~(https?://.[^\s]+)~', '<a href="$1" target="_blank">$1</a>', $text ); } $document =<<< EOD My document starts with normal text, I go on to post a link to http://interviolet.com I then explain that this is my home page, not like http://google.com which is a search engine. There are many websites on earth and my aim in life is to take over them all ... starting with http://thefirstsite.com EOD; echo replace_urls_with_links( $document ); ?> PHP:
hey thanks krakjoe. however the code doesn't work when somen types www.example.com without the http://. i need something that will work when someone includes or doesn't include the http.