Ask a Question related to PHP Development, Design and Development.
-
Ola Ekedahl #1
Find and cut string
Hi,
I'm new to PHP, so please bear with me! =)
Is there a nice little function to find a string between to html-tags?
I.e. let's say I have a string with the following text:
"Hello world, <b>this is a test</b>"
I would like to cut out the text between the <b> and </b> ("this is a test").
Thanks in advance!
Best regards
Ola Ekedahl Guest
-
can't find string with quotes
I'm trying to search for a string that contains quotes and my find statement keeps returning 0 even though I know the string exists in my... -
How to find second occurence of a string?
Hi i am using the find function which will search the first occurence of a string. but how we can find the second or third ...occurence of the... -
[PHP] find string
Isn't there an in_array function you can use? If (in_array($action, array(a1,a2,a3,a4)) { // do something } else { // do something else } -
find in string
How can i count the number of times a string appears within another string. Thanks a... -
find string between files
Hi all, how can I search for a specific string inside a directory (between files) ? Thanks for your help -
Senator Jay Billington Bulworth #2
Re: Find and cut string
In article <5cb8d6d1.0311230512.b02ff6f@posting.google.com> ,
[email]ola@ekedahl.nu[/email] (Ola Ekedahl) wrote:
Here are two ways, one with preg_match and one with list and split:> Is there a nice little function to find a string between to html-tags?
> I.e. let's say I have a string with the following text:
> "Hello world, <b>this is a test</b>"
> I would like to cut out the text between the <b> and </b> ("this is a test").
<?
$string = "Hello world, <b>this is a test</b>";
preg_match('/<b>.*<\/b>/i', $string, $result);
echo strip_tags($result[0]);
?>
<?
$string = "Hello world, <b>this is a test</b>";
list($junk, $good) = split('<b>', $string);
list($good, $junk) = split('</b>', $good);
echo $good;
?>
Both methods would get more complicated if the HTML gets more
complicated.
hth
--
Bulworth : [email]funha@fung.arg[/email] | My email address is ROT13 encoded, decode to mail
--------------------------|--------------------------------------------------
<http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!
Senator Jay Billington Bulworth Guest



Reply With Quote

