PHP code to search for part of html code above and then to p

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jole1234
Forum Newbie
Posts: 8
Joined: Fri Nov 11, 2011 10:30 am

PHP code to search for part of html code above and then to p

Post by jole1234 »

Hello.

Is there any code, script which I can use to search in some part of generated html code in page for something and then to copy that code later.

For an example.
My image gallery CMS produce page with image on it, but whatever I try I can not force CMS to give me image source path (<img src="") when I need it later. From my html code:

[text]<img src="/folder/subfolder/image-1.jpg" alt="image" width="300" height="300" />[/text]

It is normal html code generated by my CMS theme file.

What I wish is to use image source path later, this part of html code: "[text]/folder/subfolder/image-1.jpg[/text]".
For example, for image licensing, in that case image source path is needed. Look in an example of image license html code below:
[text]<a rel="license" href="http://creativecommons.org/licenses/some-license/ about="/folder/subfolder/image-1.jpg">Creative Commons some license</a>[/text]

So I need some php code to copy content between [text]<img src="[/text] and next [text]"[/text] and then later to have option to paste that content, in ths case image source path.

I hope you understand.
Best regards.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: PHP code to search for part of html code above and then

Post by twinedev »

Code: Select all

if (preg_match('/<img [^>]*src=(\'|")([^"]+)\1[^>]*>/i', $strCode,$regs)) {
    $strImgUrl = $regs[2];
}
-Greg
Post Reply