PHP: Grab (trim) a part of a string?

Discussion in 'Programming/Scripts' started by edge, Jun 12, 2007.

  1. edge

    edge Active Member Moderator

    I've got a $titleA that is set to random text "this is need" more random text

    When I do a echo $titelA; in PHP, it does show random text "this is need" more random text

    What I need is ONLY the part between the quotes (so this is need)

    In Coldfusion (my coding language) it's simply done with a "trim" option, but how do I do this in PHP?
     
  2. Ben

    Ben ISPConfig Developer ISPConfig Developer

    you could do this with
    the other thing is to do it with preg_match, like the following but this is untestet...
    PHP:
    preg_match("/\"(.*)\"/"$titleA$result);
    var_dump($result);
     
  3. edge

    edge Active Member Moderator

    Thank you Ben,

    list(,$wanted,) = explode('"', $titleA); got me going :)
     
  4. sjau

    sjau Local Meanie Moderator

    or:
    Code:
    $wanted = explode('"', $titleA);
    $wanted = $wanted[1];
    
    Note: Arrays start with element "0" so it's element "1"...
     

Share This Page