I have a few problems with this script and it`s about 48 hours i`m stuck in it and can`t find an answer on any forums or help files,so I ask you for some help.Here is the code <?php $dbname='test'; $con = mysql_connect("localhost","root","vertrigo"); mysql_select_db($dbname) or die ( "unable to select database ".$dbname); if (!$con) { die('Could not connect: ' . mysql_error()); } $pattern='Full name: </strong>([^<]+)<br> <strong>Date of birth: </strong>([^<]+)<br> <strong>Birthplace: </strong>([^<]+)<br> <strong>Nationality: </strong>([^<]+)<br>'; $dir='a'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ( $file !='.' && $file !='..' ) { $handle=fopen($file,"r"); echo "am deschis fisieru<br />"; $continut=fread($handle,filesize($file)); fclose($handle); preg_match_all($pattern,$continut,$matches,PREG_PATTERN_ORDER); $query="INSERT INTO players (name,nationality) VALUES ($matches[0][0],$matches[1][0])"; $result=mysql_query($query); } } closedir($dh); } } else echo "nu e director"; ?> Code (markup): This script is suposed to read a directory 'a' and copy a certain content(pattern) from each file and insert it into my database.I`m having a lot of problems with it. Thank you for your time..
I'm going to assume the problem is with getting your pattern to match rather than opening the file or storing values in the database once/if you get a value. I can see a few problems with your pattern You need a limiting character at the beginning and end of the pattern - the forward slash is often used. You need to use a modifier (in this case x) if you want to use whitespace in the pattern You may also need the m (multiple lines) or s (single line) modifiers to get things to work - I can't recall which way around it is.