Re: Manipulating strings

From: Date: Wed, 08 Oct 2008 08:12:37 +0000
Subject: Re: Manipulating strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-281572@lists.php.net to get a copy of this message
Ron Piggott wrote:
I have a series of questions. How do I count the number of <br /> 's in a string? How do I add text in the middle of a string, let's say after the 3rd <br /> Ron
simplest way from experience is to simply explode('<br />', $the_string) you can then count the array -1 for number of br's; and add text to the front and end of each; or indeed add/remove paragraphs before imploding it back together. If you want more power, most would say use regex or str_ functions, however I'd recommend getting used to the DOMDocument to traverse the html and make fine grained adjustments. regards, -- nathan ( nathan@kraya.co.uk ) { Senior Web Developer php + java + flex + xmpp + xml + ecmascript web development edinburgh | http://kraya.co.uk/ }

« previous php.general (#281572) next »