In article 000801c1a9c5$26007460$017f@localhost,
[EMAIL PROTECTED] (Hugh Danaher) wrote:
What I am trying to do is have a line of text break at a space after
reading 19 words. Having read the various methods of finding and replacing
one character with another, I settled on preg
PHP gave us strpos() and strrpos(), which find the first and last occurrance
of something within a string. What they forgot was rather important:
finding the nth occurrance. I wrote some code you can add to your script
(or put it in a separate file and require() it) that provides just such a
NOTE: That was done very quickly and only works on single character
searches! I'm working on one that will find multi-character strings. Gimme
a few mins and email me off-list if you want it.
Mike
Mike Frazer [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
Okay that was quicker than I thought. Here's the code to find the nth
occurrance of a string within a string:
function strnpos($string, $search, $nth) {
$count = 0;
$len = strlen($string);
$slen = strlen($search);
for ($i = 0; $i $len; $i++) {
if (($i + $slen) $len) { return FALSE; }
Mike,
Thanks for your input on this. I'm getting better at php, but it does take
time.
Thanks again,
Hugh
- Original Message -
From: Mike Frazer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, January 30, 2002 4:53 PM
Subject: [PHP] Re: preg_replace() 'space' the final frontier
5 matches
Mail list logo