1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using OR/AND in preg_replace ?

Discussion in 'PHP' started by misterdh, Jul 8, 2010.

  1. #1
    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);
    PHP:
    $shop = preg_replace('/: ([a-zA-Z0-9]*(\s){0,1})/','',$search);
    PHP:
    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 :)
     
    misterdh, Jul 8, 2010 IP
  2. misterdh

    misterdh Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Problem solved like this:

    	$shop = preg_replace('/:(\s*)([a-zA-Z0-9]*(\s){0,1})/','',$search);
    PHP:
    :cool:
     
    misterdh, Jul 8, 2010 IP