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


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=""></a>
2:<a href="smartlink:webview-something"></a>
3:<a href="link/to/something"></a>

I want to add the domain on link 3 ( but 1 and 2 should stay untouched.

How can i do that?




Try this:

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

Click on preg_replace

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


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.