select part of a word (rookie)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tdavid
Forum Newbie
Posts: 2
Joined: Thu Jun 12, 2008 5:31 pm

select part of a word (rookie)

Post by tdavid »

Howdy!

Warning! Totally rookie here. :)

I have a field in our member database, called 'latta'. it's values are usually
|||31--jan 21, 2008|||33--jan 22, 2008|||31--jan 24, 2008|||

I can grab this and explode it like this (I think, so far it worked):

Code: Select all

 
$sql = mysql_query("SELECT * FROM wsnlinks_members WHERE latta LIKE '|||31%'");  
$rowdetail = mysql_fetch_array($sql);
$data  = $rowdetail['latta'];
$pieces = explode("|||", $data);
print $pieces[1];
print $pieces[2];
 
My problem is that I need to print only the pieces that match '31%'. So using the above example, I would like to print only:
31--jan 21, 2008
31--jan 24, 2008

How can this be done?

On another note, is there a way to strip the '31--' parts before actually printing the results?

Thanks for any help, or pointers to samples dealing with something similar. Since I am not an actual php programmer (yet), I don't even know what to search for exactly for this problem. :)

Thanks again
David T.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: select part of a word (rookie)

Post by Christopher »

You could use the MySQL SUBSTR() function or the PHP substr() function. Check the manuals for each.
(#10850)
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Re: select part of a word (rookie)

Post by nincha »

use the function strstr to check
tdavid
Forum Newbie
Posts: 2
Joined: Thu Jun 12, 2008 5:31 pm

Re: select part of a word (rookie)

Post by tdavid »

Hi guys!

Thanks for the help. I will do my research on those, and will let you know. :)

Thanks
David
Post Reply