Jump to content

Recommended Posts

Hello,

 

My code:

<?php
$file = file_get_contents("https://www.amark.com/spotpricesst.asp");
$do = preg_match('/<a href="" onClick="NewWindow2('/includes/viewproduct.asp?ID=10','SpotPrice_INFO',610,300,'0','yes','center'); return false;">1 oz<\/a><\/nobr><\/td><\/tr><\/table><\/td><td class="spotsborderbottom"><table cellspacing=0 cellpadding=0 border=0><tr><td width=100%><\/td><td class="spotsnoborder">(.*)<\/td>/', $file, $matches);
if ($do) {
     print $matches['1'];

} else {
    echo "No Price";
}
?>

 

Is to pull the price of gold from this website, however the coding I am using includes an =.  Is there a way to go around this?

 

I receive the following error:

 

Parse error: syntax error, unexpected '=' in /home1/northes3/public_html/crawl/index.php on line 3

 

Thank you!

 

Link to comment
https://forums.phpfreaks.com/topic/231418-parse-error-syntax-error-unexpected-in/
Share on other sites

Dan, I am a beginner in this so I thank you for letting me know about that.  My new code is now:

<?php
$file = file_get_contents("https://www.amark.com/spotpricesst.asp");
$do = preg_match('/<a href="" onClick="NewWindow2(\'/includes/viewproduct.asp?ID=10\',\'SpotPrice_INFO\',610,300,\'0\',\'yes\',\'center\'); return false;">1 oz<\/a><\/nobr><\/td><\/tr><\/table><\/td><td class="spotsborderbottom"><table cellspacing=0 cellpadding=0 border=0><tr><td width=100%><\/td><td class="spotsnoborder">(.*)<\/td>/', $file, $matches);
if ($do) {
     print $matches['1'];

} else {
    echo "No Price";
}
?>

 

However I get:

 

Warning: preg_match() [function.preg-match]: Unknown modifier 'n' in /home1/northes3/public_html/crawl/index.php on line 3

No Price

 

I am not sure what the "n" is that it refers to?

 

I figured out to \ before any /.  Now the string:

<?php
$file = file_get_contents("https://www.amark.com/spotpricesst.asp");
$do = preg_match('/<nobr><a href="" onClick="NewWindow2(\'\/includes\/viewproduct.asp?ID=10\',\'SpotPrice_INFO\',610,300,\'0\',\'yes\',\'center\'); return false;">1 oz<\/a><\/nobr><\/td><\/tr><\/table><\/td><td class="spotsborderbottom"><table cellspacing=0 cellpadding=0 border=0><tr><td width=100%><\/td><td class="spotsnoborder">(.*)<\/td>/', $file, $matches);
if ($do) {
     print $matches['1'];

} else {
    echo "No Price";
}
?>

 

Simply doesn't find the target code.  Do you think it's just too buggy?

 

Dan,

 

Thank you so much! It works now, however it doesn't stop at the ending </td>.  It keeps on going.  Does PHP pick the first </td> or is that not specific enough for it to know when to stop?  It pulls up the whole page after the price that I want to grab.

 

My example is at: http://www.northernnightsweb.com/crawl

 

Thank you!

 

 

(.*)  <-- that selects as many things as it can, as long as the whole expression is still valid.  Regular expressions are greedy, and will match things as wide as it can.  You must use the "ungreedy" modifier to prevent this.  Change (.*) to (.*?)

 

-Dan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.