I am getting so mad can someone look at this I am trying to learn how to scrape parts off a website: <?php $data = file_get_contents('http://search.msn.com/results.aspx?q=site%3Afroogle.com'); $regex = '/Page 1 of (.+?) /results/div id="search_header"><h1>site:froogle.com</h1><h5>Page 1 of 9,138 results</h5> <b>/'; preg_match($regex,$data,$match); var_dump($match); ?> error: Warning: preg_match() [function.preg-match]: Unknown modifier 'r' in idcidkidcidkidc.php on line 4 NULL please help
I think you have to escape the '/' that appears before r. Not sure, not a big regex expert. Try putting a '\' in front of all of those and see what happens.
You are using slash as delimiters and the regex itself contains some slashes. So either escape the slashes in the regex by adding a backslash in front of them, or use a different character as delimiters (e.g.: $regex = '|Page 1 of ... <b>|';
Can someone give me an example of how to do this I can a n00b I dont know what u mean by escape the slashes. Can someone explain to a n00b how to do this?
Lesson 1: Escaping What would you do if you want a newline character in a string? $sting = "this is a \n newline."; PHP: What if you want a double quote? Sure you can alternate it. $string = 'This string contains a " in it'; PHP: Or you can "escape" it. $string = "This string contains a \" in it"; PHP: In your case: I would just use a different deliminator $regex = "%Page 1 of (.+?) /results/div id=\"search_header\"><h1>site:froogle.com</h1><h5>Page 1 of 9,138 results</h5> <b>%"; PHP: or do it the hard way. $regex = "/Page 1 of (.+?) \/results\/div id=\"search_header\"><h1>site:froogle\.com<\/h1><h5>Page 1 of 9,138 results<\/h5> <b>/"; PHP: