Jump to content


Photo

problem with pattern in preg_match_all()


  • Please log in to reply
8 replies to this topic

#1 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 21 October 2006 - 03:48 PM

Hi, I'm trying to take all links from the file with this pattern: $pattern = "/<li class=\"first\">(.*)<\/li>/"; and then when I launch site they put an error: 'You have an error in your SQL syntax near 't get the results you expected?'


Maybe someone can help me? what's wrong with it?

#2 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 22 October 2006 - 08:56 AM

Nobody know?

#3 LazyJones

LazyJones
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 22 October 2006 - 09:13 AM

The problem is not in the pattern, it's somewhere else (SQL syntax maybe......)

#4 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 22 October 2006 - 09:38 AM

$pattern = "/<li class=\"first\">(.*)<\/li>/";
preg_match_all($pattern, $fd, $matches); 
// ..............
foreach($matches[1] as $num => $bu){
       	$new_link_insert = "INSERT INTO linkai (linkai) VALUES('$bu')";
	mysql_query($new_link_insert,$db_connection) or die (mysql_error());
}
I think pattern :) But maybe is smth with SQL

#5 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 22 October 2006 - 09:41 AM

btw... when I try to make output in window.. Then It puts all file, not a links what I need....

#6 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 22 October 2006 - 12:07 PM

try going like this:
new_link_insert = "INSERT INTO linkai (linkai) VALUES('".addslashes($bu)."')";
mysql dosnt like '. so when you add slashes words like don't become don\'t. I think this should solve your problem.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#7 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 22 October 2006 - 03:52 PM

Thanks, it's working correctly, but... Like I sayed it not take all links from file, but he shows all file... I think you understand me...

#8 stebuklas

stebuklas
  • New Members
  • Pip
  • Newbie
  • 6 posts
  • LocationLithuania

Posted 23 October 2006 - 10:51 AM

please, somebody help me :)

#9 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 25 October 2006 - 10:26 AM

whats exactly wrong with it now? it isnt grabbing all the links from the text file. well if it isnt doing that smething is wrong with your pattern.
Good luck with your coding.
Jason / ProjectFear / Jaysonic




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users