PDA

View Full Version : PHP: Grab (trim) a part of a string?


edge
12th June 2007, 20:20
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?

Ben
12th June 2007, 20:51
you could do this with

list(,$wanted,) = explode('"', $titleA);


the other thing is to do it with preg_match, like the following but this is untestet...

preg_match("/\"(.*)\"/", $titleA, $result);
var_dump($result);

edge
13th June 2007, 00:02
Thank you Ben,

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

sjau
13th June 2007, 12:09
or:

$wanted = explode('"', $titleA);
$wanted = $wanted[1];


Note: Arrays start with element "0" so it's element "1"...