hi!
i have some html code like this

The Chihuahua Desert <a href="index.php">Dirt</a> Fest is <a href="/index.php">coming <a/>up, next February 17-19. <a href="http://google.com">Three</a>

i want to replace /index.php with http://google.com
and index.php with http://google.com/


and idea how can i do this

Recommended Answers

All 4 Replies

I think you can best match the domain and the path separately, and then merge them back together. Perhaps something like this:

(href=")(http://google\.com)?(/)?(.*)(")

Now you check every match, and put them back together if they are empty. [2] is the domain, [3] the slash, [4] the path. If the domain is always the same you could use a preg_replace.

echo preg_replace('%(href=")(http://google\.com)?(/)?(.*)(")%', 'href="http://google.com/$4"', $yourstring);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.