why is preg_match skipping a file and adding one at the end?
here is the code:
<?php
$files = array_diff( scandir("images/associates"), array(".", "..","_notes") );
foreach($files as $file){
echo $file,'<br />';
if (preg_match('/^692_/', $file)){
echo 'match found ';
}
else{echo 'no match found ';}
}
?>
and the result looks like this:
679_bjaad.jpg
no match found 692_Image1.jpg
match found 692_alsuitsmblur.jpg
match found 692_bjaad.jpg
match found 694_alsuitsmblur.jpg
no match found 694_blury.jpg
no match found 694_dec08.jpg
no match found 694_dec1408.jpg
no match found 694_jsuit.jpg
no match found 694_teyejaad.jpg
no match found 710_alsuitsmblur.jpg
no match found 712_bjaad.jpg
no match found
ok I think I know what it is… am I right by saying preg_match echo the file name first and then the echoed match found or not found after? inserting a break simply shift things one line?
So now that this test is working for me, would you know if I can use a code inside a string with preg_ match?
ex:
if(!empty($pic)) {
$files = array_diff( scandir(“images/associates”), array(“.”, “…”) );
foreach($files as $file){
if (preg_match('/^$user->data()->id . “"/', $file)){ --------------Where ->$user->data()->id . "” is user id followed by_ filename
echo ‘You already have a picture on file ->’.$file;
}else
{go ahead and process the rest of the script…}
}