Hi , how to check if it's a link or not in the text ? I used Preg_match function , but I think there are other nice and smart methods in PHP Any help appreciated , thanks.
I mean I'm searching for other ways , if you have some examples (not preg_match) please post them . Thanks.
preg_match is highly efficient and a good solution, as it does not cause the script to execute slowly or lag. If you are looking to check whether a variable itself is a valid URL, as opposed to a body of text containing URLs, then you could try this: <?php #checks a variable and determines if it is valid or not function valid_url ($url) { return count(@parse_url($valid_url)) > 1; } $valid_url = 'http://www.example.com/'; $invalid_url = 'example.com/help/topics/138/'; if (valid_url($valid_url)) { echo "$valid_url is a valid URL.<br />\n"; } if (valid_url($invalid_url)) { echo "$invalid_url is not a valid URL."; } ?> PHP: