You are here: Re: String Manipulation Question « All PHP « IT news, forums, messages
Re: String Manipulation Question

Posted by robert on 04/26/06 20:53

"MattMika" <mattmika@hotmail.com> wrote in message
news:u5av42t25svkgf0ihfsul60a9ldgeo5s43@4ax.com...
| Can anyone explain this to me?
|
| $string = "United Parcel Service (1 x 0.55lbs) (Ground):";
|
| $start = strrpos($string, '('); // =36
| $end = strrpos($string, ')'); // =43
| $editstring = substr($string, $start, $end);// should be strpos 36-43
|
| echo $editstring;
|
| returns - (Ground):
|
| I'm not sure why the colon is showing up. Is there a better way to
| extract the shipping type from this string?

the key is the length of characters after the starting point...you're
telling it to grab the next 43 characters that follow position 36. have a
look:

<?
$string = "United Parcel Service (1 x 0.55lbs) (Ground):";
$start = strrpos($string, '(');
$end = strrpos($string, ')');
$result = substr($string, $start, $end);
$length = ($end + 1) - $start; // 1 is offset
$expectedResult = substr($string, $start, $length);
echo '<pre>' .
print_r(
array(
'search' => $string ,
'start' => $start ,
'end' => $end ,
'length' => $length ,
'using just end' => $result ,
'using LENGTH' => $expectedResult
),
true
) .
'</pre>';
?>

hth,

me

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация