Page 1 of 1

str_replace() array error

Posted: Tue Sep 23, 2003 11:43 am
by kendall
Hello,

i have the following code which searches for url and email addresses and replaces with hyperlinks

Code: Select all

preg_match_all($exp,$_POSTї'description'],$matches);
 $desc = str_replace($matches&#1111;0],'<a href="'.$matches&#1111;0].'" target="_blank">'.$matches&#1111;0].'</a>',$_POST&#1111;'description']);			echo $desc;
However i get the following ouput
array // just says array rather than the value
Now i know about the preg_mach_callback but i work with version 4.2.3

Kendall :(

Posted: Tue Sep 23, 2003 12:19 pm
by JayBird
instead of

Code: Select all

echo $desc;
try

Code: Select all

print_r($desc);
See what you get then.

Mark

str_replace() array error

Posted: Thu Sep 25, 2003 8:12 am
by kendall
Bech1000,

all hail pimp!

i tried your suggestion however i get the same response.

the manual says the if search and replace is arrays it will loop tru the arrays.

if you observe the code the arrays are 2 dimentional so i had to use
$matches[0]
how does this affect the workings of the function? (2 dimen. arrays?)

the subject is a string of text doe...

Kendall

Posted: Thu Sep 25, 2003 12:17 pm
by pootergeist
preg_match_all returns the found occurences as an array stored in the second index

$matches[1]

the first index simply holds the search term

str_replace() array error

Posted: Thu Sep 25, 2003 12:56 pm
by kendall
pootergeist,
preg_match_all returns the found occurences as an array stored in the second index

$matches[1]

the first index simply holds the search term
i beg to differ here poo....i did a test and the value i want is held in the array $matches[0]. Even self...i tried your suggestion but it still prints out array rather than a value... for some reason its not looping thru the array.