Hi!
I've bunch of texts added in one variable, I've used my own tags to replace specific texts, something like this;
$myTexts = 'About fox: quick brown [PICTURE]fox[/PICTURE] jumps over the lazy dog<br>' .
'About lion: quick brown tiger jumps over the lazy [PICTURE]lion[/PICTURE]<br>';
Now, I'm trying to get all the texts used between "picture" tags and check if there is any file exists in image directory... on return, replace it with specific image. My following method doesn't work, any suggestion/help would be appreciated.
I wonder if preg_replace/preg_match_all can chk something in the middle of the function... something like this..:
$pictures = preg_replace('#[PICTURE](.*?)[/PICTURE]#si',
'\1', //is it possible to do something else(like checking file existence) in this line before continued?
$myTexts);
$myTexts = 'About fox: quick brown [PICTURE]fox[/PICTURE] jumps over the lazy dog<br>' . 'About lion: quick brown tiger jumps over the lazy [PICTURE]lion[/PICTURE]<br>';
//Get all text between tags... => array
if( preg_match_all('#\[PICTURE\](.*?)\[/PICTURE\]#si', $myTexts, $pictures))
{
$ePictures = $pictures[1];
}
//see if the file exists, on return true, replace it with certain picture... else replace with default picture...
for($i=0;$i<count($ePictures); $i++)
{
if(file_exists('pictures/'.$ePictures[$i].'.jpg')
{
$myTexts = str_replace('lion', '<img src="pictures/' . $ePicture[$i] . '.jpg" >', $ePictures[$i]);
}else[
$myTexts = str_replace('lion', '<img src="pictures/default.jpg">', $ePictures[$i]);
}
}
TIA