if you are using PHP later than 4, use strrpos - this will give the last index of string
Main Topics
Browse All TopicsA 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.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@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.
Not exactly sure of the format of your data. For example, do you have anything that might look like this (note there are more lines in the address and the <BR> tag is slightly different, but equally valid):
<p>Local Buiness Name<br />
148 Main St<br />
Suite 105<br/>
Philadelphia, PA<br />
Center City<br />
(215)555-0123<br />
companywebsite.com</p>
Other things you might want to consider is what the data will look like with the phone number or web site omitted. If you get a NULL placeholder for these, all is OK, but if you get something like this, it would not be so easy to get the parsing correct
<p>Local Buiness Name<br />
148 Main St<br />
Philadelphia, PA<br />
Center City<br />
companywebsite.com</p>
This code snippet teaches an easy way to deal with some of the issues. As far as speed goes, you do not even need to think about it. Any difference in parsing techniques will be invisible in the cosmic scheme of things that make up a PHP page load - you're talking microseconds in a world of milliseconds.
best regards, ~Ray
Business Accounts
Answer for Membership
by: CABISPosted on 2009-07-21 at 11:55:43ID: 24908006
I think your best bet is to do as you suggested yourself... use explode() with <br /> as your delimiter then create a new string from the array. Should be very fast and low overhead. Don't forget to add back the final "</p>"
$str = "<p>Local Buiness Name<br />148 Main Stt<br />Philadelphia, PA<br />Center City<br />(215)555-0123<br />companywebsite.com</p>";
$arr = explode("<br />", $str );
$newstr = $arr[0] . "</br>" . $arr[1] . "</br>" . $arr[2] . "</br>" . $arr[3] . "</p>" ;