Re: [PHP] whats wrong with this function

2002-07-03 Thread Adrian Murphy

thnks,
i didn't write the function so i've now replaced it
with something better.
- Original Message -
From: "Stuart Dallas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 03, 2002 2:30 PM
Subject: Re: [PHP] whats wrong with this function


> On Wednesday, July 3, 2002, 1:47:05 PM, "Adrian Murphy" wrote:
> > whats wrong with this.
> > it's getting stuck somewhere
>
> "Somewhere" isn't very helpful. When asking for help be sure to include as
much
> information as possilble.
>
> Laying out your code so the structure can be seen...
>
>  function urls_clickable($string)
> {
>   for($n=0; $n < strlen($string); $n++)
>   {
> if(strtolower($string[$n]) == 'h')
> {
>   if(!strcmp("http://";, strtolower($string[$n]) .
strtolower($string[$n+1]) . strtolower($string[$n+2]) .
strtolower($string[$n+3]) . $string[$n+4] . $string[$n+5] . $string[$n+6]))
>   {
> $startpos = $n;
>
> while($n < strlen($string) &&
eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]", $string[$n]))
>   $n++;
>
> if(!eregi("[a-z0-9]", $string[$n-1]))
>   $n--;
>
> $link = substr($string, $startpos, ($n-$startpos));
> $link = $link;
> $string_tmp = $string;
> $string = substr($string_tmp, 0, $startpos);
> $string .= "$link";
> $string .= substr($string_tmp, $n, strlen($string_tmp));
> $n = $n + 15;
>   }
> }
>   }
>   return $string;
> }
>
> $text = "http://www.somewhere.org ";
> echo urls_clickable($text);
> ?>
>
> It's getting stuck because you're moving the goalposts. It's a very bad
idea to
> base a loop on a variable that is changed within the loop. I suggest you
loop
> through one string while building a second string as the return value.
>
> On the other hand, I seem to remember seeing a regex posted on this list
> recently that did exactly this. I suggest you search the archives for it
> because it would save you a lot of hassle.
>
> --
> Stuart
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] whats wrong with this function

2002-07-03 Thread Stuart Dallas

On Wednesday, July 3, 2002, 1:47:05 PM, "Adrian Murphy" wrote:
> whats wrong with this.
> it's getting stuck somewhere

"Somewhere" isn't very helpful. When asking for help be sure to include as much
information as possilble.

Laying out your code so the structure can be seen...

http://";, strtolower($string[$n]) . strtolower($string[$n+1]) . 
strtolower($string[$n+2]) . strtolower($string[$n+3]) . $string[$n+4] . $string[$n+5] 
. $string[$n+6]))
  {
$startpos = $n;

while($n < strlen($string) && eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]", 
$string[$n]))
  $n++;

if(!eregi("[a-z0-9]", $string[$n-1]))
  $n--;

$link = substr($string, $startpos, ($n-$startpos));
$link = $link;
$string_tmp = $string;
$string = substr($string_tmp, 0, $startpos);
$string .= "$link";
$string .= substr($string_tmp, $n, strlen($string_tmp));
$n = $n + 15;
  }
}
  }
  return $string;
}

$text = "http://www.somewhere.org ";
echo urls_clickable($text);
?>

It's getting stuck because you're moving the goalposts. It's a very bad idea to
base a loop on a variable that is changed within the loop. I suggest you loop
through one string while building a second string as the return value.

On the other hand, I seem to remember seeing a regex posted on this list
recently that did exactly this. I suggest you search the archives for it
because it would save you a lot of hassle.

-- 
Stuart


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] whats wrong with this function

2002-07-03 Thread Adrian Murphy

relax friend.i was just asking

- Original Message -
From: "1LT John W. Holmes" <[EMAIL PROTECTED]>
To: "Adrian Murphy" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Wednesday, July 03, 2002 2:08 PM
Subject: Re: [PHP] whats wrong with this function


> Yes, your problem is it doesn't work.
>
> HTH,
> ---John Holmes...
>
> PS: Think that's a worthless answer? Well...same for your question...
>
> - Original Message -
> From: "Adrian Murphy" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, July 03, 2002 8:47 AM
> Subject: [PHP] whats wrong with this function
>
>
>
> whats wrong with this.
> it's getting stuck somewhere
>
>
>
> function urls_clickable($string) {
> for($n=0; $n < strlen($string); $n++)
> {
> if(strtolower($string[$n]) == 'h') {
> if(!strcmp("http://";, strtolower($string[$n]) . strtolower($string[$n+1])
.
> strtolower($string[$n+2]) . strtolower($string[$n+3]) . $string[$n+4] .
> $string[$n+5] . $string[$n+6])) {
> $startpos = $n;
> while($n < strlen($string) && eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]",
> $string[$n])) $n++;
> if(!eregi("[a-z0-9]", $string[$n-1])) $n--;
> $link = substr($string, $startpos, ($n-$startpos));
> $link = $link;
> $string_tmp = $string;
> $string = substr($string_tmp, 0, $startpos);
> $string .= "$link";
> $string .= substr($string_tmp, $n, strlen($string_tmp));
> $n = $n + 15;
> }
> }
> }
> return $string;
> }
>
> $text = "http://www.somewhere.org ";
> echo urls_clickable($text);
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] whats wrong with this function

2002-07-03 Thread 1LT John W. Holmes

Yes, your problem is it doesn't work.

HTH,
---John Holmes...

PS: Think that's a worthless answer? Well...same for your question...

- Original Message -
From: "Adrian Murphy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 03, 2002 8:47 AM
Subject: [PHP] whats wrong with this function



whats wrong with this.
it's getting stuck somewhere



function urls_clickable($string) {
for($n=0; $n < strlen($string); $n++)
{
if(strtolower($string[$n]) == 'h') {
if(!strcmp("http://";, strtolower($string[$n]) . strtolower($string[$n+1]) .
strtolower($string[$n+2]) . strtolower($string[$n+3]) . $string[$n+4] .
$string[$n+5] . $string[$n+6])) {
$startpos = $n;
while($n < strlen($string) && eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]",
$string[$n])) $n++;
if(!eregi("[a-z0-9]", $string[$n-1])) $n--;
$link = substr($string, $startpos, ($n-$startpos));
$link = $link;
$string_tmp = $string;
$string = substr($string_tmp, 0, $startpos);
$string .= "$link";
$string .= substr($string_tmp, $n, strlen($string_tmp));
$n = $n + 15;
}
}
}
return $string;
}

$text = "http://www.somewhere.org ";
echo urls_clickable($text);



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] whats wrong with this function

2002-07-03 Thread Jason Wong

On Wednesday 03 July 2002 20:47, Adrian Murphy wrote:
> whats wrong with this.
> it's getting stuck somewhere

Stick in some echo statements at strategic points in the loops to find out 
_where_ it is getting stuck.

> function urls_clickable($string) {
> for($n=0; $n < strlen($string); $n++)
> {
> if(strtolower($string[$n]) == 'h') {
> if(!strcmp("http://";, strtolower($string[$n]) . strtolower($string[$n+1]) .
> strtolower($string[$n+2]) . strtolower($string[$n+3]) . $string[$n+4] .
> $string[$n+5] . $string[$n+6])) { $startpos = $n;
> while($n < strlen($string) && eregi("[a-z0-9\.\:\?\/\~\-\_\&\=\%\+\'\"]",
> $string[$n])) $n++; if(!eregi("[a-z0-9]", $string[$n-1])) $n--;
> $link = substr($string, $startpos, ($n-$startpos));
> $link = $link;
> $string_tmp = $string;
> $string = substr($string_tmp, 0, $startpos);
> $string .= "$link";
> $string .= substr($string_tmp, $n, strlen($string_tmp));
> $n = $n + 15;
> }
> }
> }
> return $string;
> }
>
> $text = "http://www.somewhere.org ";
> echo urls_clickable($text);


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
System going down at 1:45 this afternoon for disk crashing.
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php