gwkg
asked on
Which PHP Str Function to Use For This....
A funciton in Wordpress is returning this
<p>Local Buiness Name<br />
148 Main Stt<br />
Philadelphia, PA<br />
Center City<br />
(215)555-0123<br />
companywebsite.com</p>
What is the appropriate function to use to cut out what is in bold
<br />
(215)555-0123<br />
companywebsite.com
And only leave
<p>Local Buiness Name<br />
148 Main St<br />
Philadelphia, PA<br />
Center City</p>
The actual data will be different each time so I can't use anything that counts the characters.
Should I use explode() at the <br /> tags and then rebuild the output from the pieces or is there a way to chop off everything at the 4th <br /> ?
I'd like to choose based on execution speed, if possible.
<p>Local Buiness Name<br />
148 Main Stt<br />
Philadelphia, PA<br />
Center City<br />
(215)555-0123<br />
companywebsite.com</p>
What is the appropriate function to use to cut out what is in bold
<br />
(215)555-0123<br />
companywebsite.com
And only leave
<p>Local Buiness Name<br />
148 Main St<br />
Philadelphia, PA<br />
Center City</p>
The actual data will be different each time so I can't use anything that counts the characters.
Should I use explode() at the <br /> tags and then rebuild the output from the pieces or is there a way to chop off everything at the 4th <br /> ?
I'd like to choose based on execution speed, if possible.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@dhiraj05: thanks, except that its not the last <br /> I need the pos of, its the 2nd to last <br /> . Theres 5 <br /> tags, I want to lose the 4th one and everything after it.
@CABUS: thats pretty much what I have now, thanks for confirming its speed
$pieces = explode("<br />",$text);
for($i=0;$i<4;$i++)
$excerpt .= $pieces[$i]."<br />";
return $excerpt;
i'll leave it open for the night and award the points in the morning.
@CABUS: thats pretty much what I have now, thanks for confirming its speed
$pieces = explode("<br />",$text);
for($i=0;$i<4;$i++)
$excerpt .= $pieces[$i]."<br />";
return $excerpt;
i'll leave it open for the night and award the points in the morning.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone! I didn't know about var_dump (was using print_r) nor strrpos before this question, and will use unset in my new function =)
Thanks for the points - it's a good questions. ~Ray
Thanks for the points... :)
Open in new window