Kovo Posted August 22, 2009 Share Posted August 22, 2009 Hello all,I really tried hard to avoid asking on the forums, but after an hour, I just cant get this to work and its bugging me.I want to know if someone can help me out with the regex I need to find the folliwng in a string and replace it (using PHP) $current=preg_replace("/\bdefine('HOST_NAME','');\b/","define('HOST_NAME','".$HOST_NAME."');",$current); Heres my problem: define('HOST_NAME','') can either have an empty value as the example above, or something already set like so: define('HOST_NAME','a host name'); So obviously my current preg_replace function wont work al lthe time (or at all)Any help would be greatly appreciated! Link to comment Share on other sites More sharing options...
Ingolme Posted August 22, 2009 Share Posted August 22, 2009 There's another mistake: parenthsis are reserved characters and should be escaped.You can just check for 0 or more characters if there may or may not be a host name already:/\bdefine\('HOST_NAME','[^']*'\);\b/ Link to comment Share on other sites More sharing options...
Kovo Posted August 22, 2009 Author Share Posted August 22, 2009 Thanks! I just had to remove the \b at the beginning and end as well! Much appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.