[ale] php weirdness

James Sumners james.sumners at gmail.com
Mon Feb 23 12:50:17 EST 2009


The following does exactly what you want:
---------------------------------
<?php
$foo = "abc12345";
$foo2 = substr_replace($foo, '-', 0, 3);
$foo3 = str_replace(substr($foo, 0, 3), '-', $foo);
print("foo = ".$foo."\n");
print("foo2 = ".$foo2."\n");
print("foo3 = ".$foo3."\n");
?>
----------------------------------

This is the output from my installation of PHP:
----------------------------------
[mythtv at mythtv tmp]$ php -v && php test.php
PHP 5.2.7 with Suhosin-Patch 0.9.6.3 (cli) (built: Dec  6 2008 19:19:58)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
foo = abc123456
foo2 = -123456
foo3 = -123456
----------------------------------

We have done nothing different according to what you have posted. So
there must be something else modifying your string.

On Mon, Feb 23, 2009 at 12:24 PM, Jim Kinney <jim.kinney at gmail.com> wrote:
> Why does
>
> echo str_replace(substr($row['foo'],0,3), '-', $row['foo']);
>
> print out    abc-12345
>
> when $row['foo'] contains abc12345? From what str_replace is SUPPOSED
> to do it should print -12345 instead??
>
> php5.



-- 
James Sumners
http://james.roomfullofmirrors.com/

"All governments suffer a recurring problem: Power attracts
pathological personalities. It is not that power corrupts but that it
is magnetic to the corruptible. Such people have a tendency to become
drunk on violence, a condition to which they are quickly addicted."

Missionaria Protectiva, Text QIV (decto)
CH:D 59


More information about the Ale mailing list