how to remove
onmousedown="return curwt(this, 'http://www.example.com/2009/07/content.html')"
using str_replace( )
, i know how to use this string but can not understand the way to configure this string to remove onmousedown="all content"
in this way.
I have tried in this way: $result = str_replace("onmousedown''", " ", $result);
But it will not work.. any idea?
Asked
Active
Viewed 104 times
-2

user1642787
- 75
- 1
- 2
- 7
-
2Use `preg_replace()` instead. `str_replace()` doesn't let you use wildcards like that. – ceejayoz Sep 06 '12 at 16:18
2 Answers
4
I think that you want to use a regular expression
$result = preg_replace('/onmousedown=".*?"/', '', $result);
Or if it can be both apostrophes and quotes:
$result = preg_replace('/onmousedown=("|\').*?\1/', '', $result);

Explosion Pills
- 188,624
- 52
- 326
- 405
-
thanks, one more question is it ok> `$result = str_replace( 'href="', "href='http://site.com/visit.html?", $result);` – user1642787 Sep 06 '12 at 16:45
-
It's okay in that it will work.. I can't say whether it will do what you want it to do. – Explosion Pills Sep 06 '12 at 16:51
0
You can't use str_replace for this, because it can only replace pre-defined strings, no wildcards.
You can use preg_replace for this.

Daniel M
- 3,369
- 20
- 30