...

View Full Version : Programmer's Block - Ripping out part of a string



rswyatt
05-11-2004, 02:36 PM
Good morning, afternoon and evening!

I'm experiencing the dreaded programmer's block.

I have a string $row['isbn'].

It contains a number like: 0830814574

I want to catch only these digits of the string: 0830814574.

I cannot for the life of me remember which PHP function assists me in this.

Any help would be greatly appreciated. :-)

Thanks,
Rich

sidney
05-11-2004, 02:50 PM
if the numbers are in the same position then you could use substr()

http://uk.php.net/manual/en/function.substr.php

rswyatt
05-11-2004, 02:52 PM
Goooooooood grief...

Thank the Lord for forums... I've only used substr() hundreds of times.. I guess I know what writers go through now, suddenly having no idea what to write. :D

Thanks Sydney!

Rich

sidney
05-11-2004, 02:57 PM
you could also use substring() in your mysql query to only retrive the substring you want

http://dev.mysql.com/doc/mysql/en/String_functions.html

strbubs44@sbcgl
03-04-2005, 05:35 PM
I have a field that has :
SMTP:{email@email.com}blahblahblah
I need the characters in between the {}, no matter what the length is.
I can always tell the starting position, but cannot tell the ending }

bcarl314
03-04-2005, 06:02 PM
probably be best off with preg_match() in that case...

Something like...



$str = "SMTP:{email@email.com}blahblahblah";
$matches = preg_match_all("/^SMTP:\{(.*?)\}\w*/",$str);
print_r($matches); //shows what matched.
print $matches[1]; //should be the matched string.


Should to the trick. Not tested though.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum