Page 1 of 1

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

Posted: Thu Dec 01, 2011 8:04 am
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.

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

Posted: Thu Dec 01, 2011 8:45 am
by twinedev

Code: Select all

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