I have the following header:
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Expires: -1 Pragma: no-cache Cache-Control: no-cache Set-Cookie: JSESSIONID=74E66481C486668AA1DDDEED2F7A37A8; Path=/travelsearch Content-Type: text/xml;charset=ISO-8859-1 Content-Length: 97 Date: Thu, 11 May 2006 14:01:28 GMT OK
-------------
And I want to extract a substring starting from the begining till *GMT* at the end, but leavign out the last *OK*.
PS: There are two Oks in the entire string. i'm new to php5 so not very familiar with the api. :p
String manipulation in PHP 5
Moderator: General Moderators
- ambivalent
- Forum Contributor
- Posts: 173
- Joined: Thu Apr 14, 2005 8:58 pm
- Location: Toronto, ON
substr() should do what you need.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Yes you are right, the simple strstr doesnt work, it works only for single character. I have solved the problem though
public function strring_strrpos($haystack,$needle){
while($return = strrpos($haystack,$needle))
{
if(strncmp(substr($haystack,$return,strlen($needle)),
$needle,strlen($needle)) == 0 )
return $return;
$haystack = substr($haystack,0,$return -1 );
}
return $return;
}
public function strring_strrpos($haystack,$needle){
while($return = strrpos($haystack,$needle))
{
if(strncmp(substr($haystack,$return,strlen($needle)),
$needle,strlen($needle)) == 0 )
return $return;
$haystack = substr($haystack,0,$return -1 );
}
return $return;
}