Jump to content

Regex Issues


discussnow

Recommended Posts

Hello, I'm currently working on using regex to scrape a few lines of code and display it:

 

$scrape = file_get_the_contents($url) ; 
$regex = '/<td class="info">    <a href="(.+?)" title=/';
preg_match($regex,$scrape,$results);
var_dump($results);
echo $results;

 

and this is the result I get : array(2) { [0]=>  string(61) "

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/
Share on other sites

Hello, I'm currently working on using regex to scrape a few lines of code and display it:

 

$scrape = file_get_the_contents($url) ; 
$regex = '/<td class="info">    <a href="(.+?)" title=/';
preg_match($regex,$scrape,$results);
var_dump($results);
echo $results;

 

and this is the result I get : array(2) { [0]=>  string(61) "

 

 

so...what's the problem?

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696011
Share on other sites

a) How are we to know which URL you are scraping? (file_get_the_contents($url) doesn't tell us what the source code is)

b) In your pattern '/<td class="info">    <a href="(.+?)" title=/', I hope you realise that those spaces between the td tag and the a tag are actually needed to be matched (if you do not desire those spaces, remove them from the pattern).

c) an answer like 'and this is the result I get : array(2) { =>  string(61) " ' doesn't tell us squat.

 

My advice would be to provide a sample of the URL code you are trying to scrape, as your post tells us nothing (other than the involement of a td tag and an a tag (with some spaces in between for some odd reason).

Link to comment
https://forums.phpfreaks.com/topic/133691-regex-issues/#findComment-696646
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.