I have a string in php that looks like this
$(window).load(function(){
$('.someclass').click(function () {
$(this).text("clicked");
});
});
what i want is - if string contains $(window).load(function(){ then replace this and also the end braces }); with empty string ""
But if $(window).load(function(){ do not exist then do nothing.
Here is what i have tried:
if(strpos($str,"$(window).load(function(){") == -1){
// do nothing
}
else{
str_replace("$(window).load(function(){","",$str);
// how do i replace the last }); with ""
}
.loaddirectly on the page?.loadis written like this:$(window).load( function() {(note extra spaces). Arguably this can be resolved by using regex but IMO it will be an error prone operation.