php - preg_replace href value only if there string x is not found in it

347

I have a problem with the following situation

I want to replace the href value with preg_replace and dont know how

I got 3 types of links

1:<a href="http://www.something.com"></a>
2:<a href="smartlink:webview-something"></a>
3:<a href="link/to/something"></a>

I want to add the domain on link 3 (http://www.something.com/link/to/something) but 1 and 2 should stay untouched.

How can i do that?

599

Answer

Solution:

Try this:

 $new_link = preg_replace("/href=\\"(?!(http|smartlink))(.*)\\">/", "http://www.something.com/$2", $str);

Click on preg_replace
http://www.phpliveregex.com/p/fJ9

People are also looking for solutions to the problem: php - MailChimp sending incorrect user IDs

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.