Sophie Mattoug wrote:
Adam i Agnieszka Gasiorowski FNORD wrote:
I'm trying to develop a regex for matching
with preg_match_all, I want to match such things
like image name, image alt text, image title in
construct like this:
....html...
<div class="class" style="style">
<img src="img=name" alt="alt" title="title" />
<span class="class" style="style">
text
</span>
</div>
....html...
The rexex as for now is:
define(
'REGEX_IMAGE_NAMES_AND_TITLES_AND_ALTS_FROM_CONTENT',
'{
(?:<\s*img\s+src\s*=\s*(?:"|\')?\s*(?:img)?\s*=\s*) #
<img>
(?>\b\S+\b) # name
(?:title\s*=\s*(?:"|\')) #
title
(?>\b\S*\b)
(?:"|\')*\s*
(?:alt\s*=\s*(?:"|\')) # alt
(?>\b\S*\b)
(?:"|\')*\s*
(?:\"|\'|>|/>|\s) # <img />
}Uix'
);
, but it does not match. How can I fix it?
It's not so easy to match an entire IMG tag, because first of all the
attributes are not always in the same order. If I were you, this is
what I would do :
ereg("<img ([^>]+)>", $your_text, $img_array);
$i = 0;
foreach ($img_array as $img) {
while (ereg("^(.+)=\"(.+)\"", "", $img, $regs))
$images[$i][$regs[1]] = $regs[2];
$i++;
}
Hope this helps,
Sorry I made a mistake. Better do this:
ereg("<img ([^>]+)>", $your_text, $img_array);
$i = 0;
foreach ($img_array as $img) {
while (ereg("^(.+)=\"(.+)\"(.+)$", "", $img, $regs)) {
$images[$i][$regs[1]] = $regs[2];
$img = $regs[3];
}
$i++;
}
--
Cordialement,
---------------------------
Sophie Mattoug
Développement web dynamique
[EMAIL PROTECTED]
---------------------------
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php