More simple by using the 'e' modifier on the regexp IMO. E.g.
$imagemap = preg_replace("/href=\"([^\
I hope it helps,
Zoltan
Main Topics
Browse All TopicsI'm storing the html for many image maps in a mysql database, when the html is loaded I want to extend the urls for the area href's. Each image map will include several href's, each with a ref eg href="29". What I need to do when the html is loaded is extend the href to eg:
href="' . tep_href_link(FILENAME_DEF
where tep_href_link is a function and FILENAME_DEFAULT and $cPath are parameters.
The nearest I can get is:
$imagemap = str_replace('href="29"', 'href="' . tep_href_link(FILENAME_DEF
But '29' will be a value which differs for each area of the image map. Would ereg_replace solve the problem?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
vorbe, this almost worked using the following code:
function replace_one($group_cat_ids
global $cPath, $page;
return 'href="' . tep_href_link(FILENAME_DEF
}
I build the array $group_cat_ids - code not shown - array values are 29, 30, 31, 32
The next line modifies each href and retains the above values in one call - don't quite understand that as the above function
only references the first value in the array $group_cat_ids[0].
$imagemap = preg_replace_callback("/hr
The typical result in the imagemap html is:
href="http://10.0.0.3/pewt
What is not quite correct is the _href="29"
I need to remove the href=" and second "
I see what is happening, it is retaining the search string href="29" and prefixing, where as I'm hoping to get the following:
href="http://10.0.0.3/pewt
Actually the callback function gets a special array. At position 0 is the whole match, that is href="29" in the example. At position 1 is only 29, i.e. the part in the parentheses (if you look at the regular expression). I understood you needed only that string, not the whole href="29" string so I used that - $matches[1] (not $matches[0]).
That should be like this:
function replace_one($group_cat_ids
global $cPath, $page;
return 'href="' . tep_href_link(FILENAME_DEF
}
Sorry for missing to set global those vars in my example ;)
Sorry, the usual problem when typed directly here. The correct one is
$imagemap = preg_replace("/(href\s*=\s
I have tested with this script now and worked.
<?php
define("FILENAME_DEFAULT",
$cPath = "path/";
$imagemap = 'href = "hihi.html" href="haha.html"';
$imagemap = preg_replace("/(href\s*=\s
function tep_href_link($a, $b)
{
return $a . $b;
}
echo $imagemap;
?>
Business Accounts
Answer for Membership
by: vorbePosted on 2006-03-28 at 04:03:35ID: 16309625
Doing it with ereg_replace is not really an option -- it replaces only the first occurence, unlike str_replace and preg_replace. An easy way to do it with preg_replace_callback:
AULT, $cPath . '_' . $matches[1]) . '"';
ef=\"([^\" ]*)\"/i", "replace_one", $imagemap);
// this function replaces one occurence of the pattern
// in $matches[1] is the text between ""
function replace_one($matches) {
return 'href="' . tep_href_link(FILENAME_DEF
}
// the pattern searches for href="..." and isolates the text between "" using ()
$imagemap = preg_replace_callback("/hr