Jump to content

[SOLVED] Array not working


gtal3x

Recommended Posts

For some reason the variable $smilies wont return the img puth instead is displaying "Array" anny solution?

<?php
$body = "";

function smilies($text)
{
$smilies = array(
  "" => "smile1.gif",
  "" => "wink.gif",
  "" => "grin.gif"
);

$smiliesK = array_keys($smilies);
$newtext = str_replace($smiliesK, "<img src='images/smilies/$smilies'>", $text); // The error is here in $smilies
return $newtext;
}


echo smilies($body);
?>

Link to comment
https://forums.phpfreaks.com/topic/75577-solved-array-not-working/
Share on other sites

<?php
$body = "";

function smilies($text)
{
$smilies = array(
  "" => "smile1.gif",
  "" => "wink.gif",
  "" => "grin.gif"
);

$images = array();
foreach($smilies as $smile => $filename)
$images[$smile] = "<img src='images/smilies/".$filename."'>";

$smiliesK = array_keys($smilies);
$newtext = str_replace($smiliesK, $images, $text); // The error is here in $smilies
return $newtext;
}


echo smilies($body);
?>

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.