[PHP] Showing only part of string

2004-05-07 Thread Dave Carrera
Hi List,

$string = This is a test string to titleSHOW ONLY THIS BIT/title of the
string;

I have tried strpos, str_replace and other string manipulation things but I
cant get my head around how to achieve showing the text with the
title/title tags of the string.

Any help is appreciated and I thank you in advance for any help given.

Thank you

Dave Carrera


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.677 / Virus Database: 439 - Release Date: 04/05/2004
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Showing only part of string

2004-05-07 Thread Richard Harb
I guess the easiest way to do this would be to use a regular
expression:

if (preg_match(/title(.*)\/title/i, $string, $m)) {
$found = $m[1];
}
echo $found;

Richard


Friday, May 7, 2004, 12:11:02 PM, thus was written:
 Hi List,

 $string = This is a test string to titleSHOW ONLY THIS BIT/title of the
 string;

 I have tried strpos, str_replace and other string manipulation things but I
 cant get my head around how to achieve showing the text with the
 title/title tags of the string.

 Any help is appreciated and I thank you in advance for any help given.

 Thank you

 Dave Carrera

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Showing only part of string

2004-05-07 Thread John W. Holmes
Dave Carrera wrote:

$string = This is a test string to titleSHOW ONLY THIS BIT/title of the
string;
I have tried strpos, str_replace and other string manipulation things but I
cant get my head around how to achieve showing the text with the
title/title tags of the string.
Any help is appreciated and I thank you in advance for any help given.
$b = strpos($str,'title')+7;
$l = strpos($str,'/title') - $b;
$m = substr($str,$b,$l);
Sure, you can use regular expressions, but there's not really a need 
unless this gets more complex. Even though you're executing more code 
with this solution, it'll be faster than preg_match() (go ahead and 
benchmark it).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Showing only part of string

2004-05-07 Thread Dave Carrera
Thanks John,

Works a treat.

Thank You

Dave Carrera


-Original Message-
From: John W. Holmes [mailto:[EMAIL PROTECTED] 
Sent: 07 May 2004 12:32
To: Dave Carrera
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Showing only part of string


Dave Carrera wrote:

 $string = This is a test string to titleSHOW ONLY THIS BIT/title 
 of the string;
 
 I have tried strpos, str_replace and other string manipulation things 
 but I cant get my head around how to achieve showing the text with the 
 title/title tags of the string.
 
 Any help is appreciated and I thank you in advance for any help given.

 $b = strpos($str,'title')+7;
 $l = strpos($str,'/title') - $b;
 $m = substr($str,$b,$l);

Sure, you can use regular expressions, but there's not really a need 
unless this gets more complex. Even though you're executing more code 
with this solution, it'll be faster than preg_match() (go ahead and 
benchmark it).

-- 
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.677 / Virus Database: 439 - Release Date: 04/05/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.677 / Virus Database: 439 - Release Date: 04/05/2004
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php