Modernvox Posted November 3, 2009 Share Posted November 3, 2009 Error reads unexpected T_STRING Line causing the error echo "Link = " . $set['link'] ", E-mail = " . $set['email'] . "<br/>"; complete code <?php $links = fetch_links("http://southcoast.craigslist.org/sss/"); $sets = array(); foreach($links as $link) { $sets[] = fetch_email($link); } foreach($sets as $set) { $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set'); mysql_close($dbx); echo "Link = " . $set['link'] ", E-mail = " . $set['email'] . "<br/>"; } function fetch_links($page_url) { $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; $page = file_get_contents($page_url); preg_match_all($pattern, $page, $matches); return $matches[1]; } function fetch_email($page_link) { $pattern = '#(sale-[a-z0-9]+-\d+@craigslist\.org)#'; $page = file_get_contents("http://southcoast.craigslist.org" . $page_link); preg_match($pattern, $page, $out); return array('link'=>$page_link, 'email'=>$out[1]); } endforeach; ?> Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/ Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 the problem is here mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set'); Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949825 Share on other sites More sharing options...
salathe Posted November 3, 2009 Share Posted November 3, 2009 echo "Link = " . $set['link'] ", E-mail = " . $set['email'] . "<br/>"; // look here ^ missing period/dot between ] and " Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949827 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 the problem is here mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set'); And why is that? Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949828 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 echo "Link = " . $set['link'] ", E-mail = " . $set['email'] . "<br/>"; // look here ^ missing period/dot between ] and " Nope. Did nothing :'( Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949830 Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 http://www.parse-error-unexpected-t-string.com/ Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949832 Share on other sites More sharing options...
trq Posted November 3, 2009 Share Posted November 3, 2009 the problem is here mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set'); And why is that? You don't close the string or the function params. mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949833 Share on other sites More sharing options...
salathe Posted November 3, 2009 Share Posted November 3, 2009 Nope. Did nothing :'( You didn't just copy/paste my code did you? Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949840 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 http://www.parse-error-unexpected-t-string.com/ lol. Had this page open while reading threads. Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949843 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 Nope. Did nothing :'( You didn't just copy/paste my code did you? lol. No Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949844 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 the problem is here mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set'); And why is that? You don't close the string or the function params. mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); After fixing this the endforeach; is unexpected everywhere i try to put Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949845 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 Hmm...I found just one spot to put the endforeach; statement , but results in an infinite loop i am guessing since the page just kept loading. Anyone know where the endforeach: statement is suppose to be? Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949855 Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 What's block does the endforeach; at the end relate to ? to help you i have formatted the code (to make it more visible) <?php $links = fetch_links("http://southcoast.craigslist.org/sss/"); $sets = array(); foreach($links as $link) { $sets[] = fetch_email($link); } foreach($sets as $set) { $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); mysql_close($dbx); echo "Link = " . $set['link'] .", E-mail = " . $set['email'] . "<br/>"; } function fetch_links($page_url) { $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; $page = file_get_contents($page_url); preg_match_all($pattern, $page, $matches); return $matches[1]; } function fetch_email($page_link) { $pattern = '#(sale-[a-z0-9]+-\d+@craigslist\.org)#'; $page = file_get_contents("http://southcoast.craigslist.org" . $page_link); preg_match($pattern, $page, $out); return array('link'=>$page_link, 'email'=>$out[1]); } endforeach; ?> Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949862 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 What's block does the endforeach; at the end relate to ? to help you i have formatted the code (to make it more visible) <?php $links = fetch_links("http://southcoast.craigslist.org/sss/"); $sets = array(); foreach($links as $link) { $sets[] = fetch_email($link); } foreach($sets as $set) { $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); mysql_close($dbx); echo "Link = " . $set['link'] .", E-mail = " . $set['email'] . "<br/>"; } function fetch_links($page_url) { $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; $page = file_get_contents($page_url); preg_match_all($pattern, $page, $matches); return $matches[1]; } function fetch_email($page_link) { $pattern = '#(sale-[a-z0-9]+-\d+@craigslist\.org)#'; $page = file_get_contents("http://southcoast.craigslist.org" . $page_link); preg_match($pattern, $page, $out); return array('link'=>$page_link, 'email'=>$out[1]); } endforeach; ?> It relates to foreach($sets as $set) { Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949864 Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 But that block ends foreach($sets as $set) { $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); mysql_close($dbx); echo "Link = " . $set['link'] .", E-mail = " . $set['email'] . "<br/>"; }//<----------HERE-------- Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949878 Share on other sites More sharing options...
Modernvox Posted November 3, 2009 Author Share Posted November 3, 2009 But that block ends foreach($sets as $set) { $dbx= mysql_connect("localhost", "root", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$set')"); mysql_close($dbx); echo "Link = " . $set['link'] .", E-mail = " . $set['email'] . "<br/>"; }//<----------HERE-------- Well for some reason beyond my knowledge the foreach is causing the script to load forever? Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-949890 Share on other sites More sharing options...
MadTechie Posted November 3, 2009 Share Posted November 3, 2009 endforeach; isn't needed, as all foreach'es already have opening { and a closing } Link to comment https://forums.phpfreaks.com/topic/180040-solved-do-you-see-a-syntax-error-in-this-one-line-of-code/#findComment-950018 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.