I use codeigniter and want check if exists a url in content other url, return is true else it is false.
for example i want chack for url http://chat.stackoverflow.com/ that did there is in page http://stackoverflow.com/ or no.
I tried as, it have error:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://stackoverflow.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
$link="http://chat.stackoverflow.com/";
if(preg_match($link,$contents) && stripos($contents,"chat.stackoverflow")){
echo "yes";
}else{
echo "no";
}
?>
Output is as:
Warning: preg_match(): Delimiter must not be alphanumeric or backslash in /code/O4savv on line 8
no
Demo: http://codepad.viper-7.com/O4savv
How is fix it?
You need to add a leading and ending forward slash to the pattern for the regular expression. And also, escape the forward slash that is part of the pattern you’re trying to match to avoid conflict.
http://codepad.viper-7.com/PWMVzl