close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

failing to properly access array created by preg_match

Thread began 1/30/2022 5:31 am by yogastudents362523 | Last modified 1/31/2022 1:17 pm by yogastudents362523 | 461 views | 4 replies

yogastudents362523

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).

Attached Files
presenter_switchboard_thumbimage_update.php

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...