Jump to content

Using OR/AND in preg_replace ?


dominod

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.