failing to properly access array created by preg_match
Hello,
You may recall that as per this code snippet:
<?php $shortbio = preg_replace("/<img[^>]+\>/i", "", $rsAllPresenterData->getColumnVal("Biography",false)) ; ?>
<?php $shortbio = substr($shortbio, 0, 550) ; ?>
you assisted me with the preg_replace function. (I had foolishly placed the substr request BEFORE the remove references to images request; and you fixed my issue by inverting the code order; and as given above).
I am now having a problem with the complementary preg_match function.
preg_match is supposed to examine the data, count the number of matching instances, and return an array of all images in the provided HTML code snippet. But either I am not receiving that array; or else the code I write is mistaken (more likely).
I am providing workable material, because:
echo($rsAllPresenterData->getColumnVal("Biography",false)) ;
correctly displays Presenter Bios on the page, including all images.
I then use preg_match as follows.
(I felt it best to leave my little foolish 'echo' notes to myself in place so you can correct my logic if necessary):
echo('This is before the preg_match and its print_r, thus indicating success in matching<br />');
print_r(preg_match("/<img[^>]+\>/i", $rsAllPresenterData->getColumnVal("Biography",false), $matches, PREG_OFFSET_CAPTURE)) ;
echo('<br />And this is before the print_r of those $matches <br />');
print_r($matches) ;
echo('<br />This is after all that<br /> and then here, supposedly, is the foreach<br /> ');
foreach($matches as $myinfo)
{
print_r($myinfo);
}
The first print_r displays a '1' (to show success in matching of some kind).
The second print_r displays only the first image in the bio, along with the text:
Array ( [0] => Array ( [0] => [1] => 0 ) )
And the third print_r again displays only the first image in the bio, along with the shorter text:
Array ( [0] => [1] => 0 )
I have attached the file concerned.
Thank you,
KAB
(And in case it makes a difference, then I am trying to create a dynamic menu (option-select) containing the precise names of all the image files Presenter use in their longer biographies.
I am already extracting the first 500 characters, without images, of their long bio to create a more general listing of all Presenters. But that short bio nevertheless needs an image. I at first thought I could leave them to copy and paste the relevant filename into a datbase field and update the database. But as you will appreciate, this has its rather large issues. I need an easier and more automatic process. A menu will faultlessly and accurately contain the precise filenames of all images in their bio, and they can then select to indicate which image they want me to use. I already have coding to place the correct image from the filemanager's thumbs directory in place. Thank you. But I can't get the above preg_match to work. Thank you).