dominod Posted July 8, 2010 Share Posted July 8, 2010 Hi I want to use two lines for on string in preg_replace.. I want the following two codes to work: $shop = preg_replace('/:([a-zA-Z0-9]*(\s){0,1})/','',$search); $shop = preg_replace('/: ([a-zA-Z0-9]*(\s){0,1})/','',$search); The difference between them is that the second one got space between ":" and "([a..".. The problem I am trying to solve is this.. When I use the first line of code and type in "keyword: wordkey" it echo "keywordwordkey" instead of "keyword" as it shuld and does when I enter "keyword:wordkey" (without the space). When I am using the other line of code and type in "keyword:wordkey" it echo "keyword:wordkey" and not "keyword" is it shuld and does when I enter "keyword: wordkey" (with the space). What I want is that it echos "keyword" no matter if there is a space there or not .. Does anyone know how to fix this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/207131-using-orand-in-preg_replace/ Share on other sites More sharing options...
dominod Posted July 8, 2010 Author Share Posted July 8, 2010 Problem solved like this: $shop = preg_replace('/:(\s*)([a-zA-Z0-9]*(\s){0,1})/','',$search); Link to comment https://forums.phpfreaks.com/topic/207131-using-orand-in-preg_replace/#findComment-1083003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.