Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 12th June 2007, 20:20
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,036
Thanks: 268
Thanked 152 Times in 132 Posts
Default PHP: Grab (trim) a part of a string?

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?
__________________
Never execute code written on a Friday or a Monday.
Reply With Quote
Sponsored Links
  #2  
Old 12th June 2007, 20:51
Ben Ben is offline
Moderator
 
Join Date: Jul 2006
Posts: 1,029
Thanks: 7
Thanked 62 Times in 56 Posts
Default

you could do this with
Quote:
list(,$wanted,) = explode('"', $titleA);
the other thing is to do it with preg_match, like the following but this is untestet...
PHP Code:
preg_match("/\"(.*)\"/"$titleA$result);
var_dump($result); 
Reply With Quote
The Following User Says Thank You to Ben For This Useful Post:
edge (13th June 2007)
  #3  
Old 13th June 2007, 00:02
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,036
Thanks: 268
Thanked 152 Times in 132 Posts
Default

Thank you Ben,

list(,$wanted,) = explode('"', $titleA); got me going :-)
__________________
Never execute code written on a Friday or a Monday.
Reply With Quote
  #4  
Old 13th June 2007, 12:09
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
 
Default

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

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
Slightly Confused (DNS & Server Help) JohnnyBGoode Installation/Configuration 26 14th August 2007 09:54
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18
php script injections Grizzly General 21 18th July 2006 08:55


All times are GMT +2. The time now is 04:35.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.