str_replace() array error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

str_replace() array error

Post 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 :(
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

instead of

Code: Select all

echo $desc;
try

Code: Select all

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

Mark
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

str_replace() array error

Post 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
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post 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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

str_replace() array error

Post 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.
Post Reply