tserfer Posted November 15, 2013 Share Posted November 15, 2013 Helllo guys Lets say we have 2 strings that we want to replace . For example 1) rand( 2) mt_rand( (I know that these 2 are functions but lets say that they are strings). If i do: $source = preg_replace( "/rand\(/","NEW"); it will Replace the mt_rand as well and it will become mt_NEW( How can i fix it so that it will replace the whole function and not a part of it? We are talking about functions in strings Hope you understand Thanks Link to comment https://forums.phpfreaks.com/topic/283925-preg-replace-question/ Share on other sites More sharing options...
MDCode Posted November 15, 2013 Share Posted November 15, 2013 If there isn't a possible conflict, why not check for rand with a space in front, or not with an underscore in front? Link to comment https://forums.phpfreaks.com/topic/283925-preg-replace-question/#findComment-1458405 Share on other sites More sharing options...
.josh Posted November 15, 2013 Share Posted November 15, 2013 $string = preg_replace('~\brand\(~','new',$string); Link to comment https://forums.phpfreaks.com/topic/283925-preg-replace-question/#findComment-1458432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.