Forum Moderators: coopster
$a[filename] = strtolower($a[term]);
$a[example] = str_replace(",", ' + ', $row[example_string]);
$a[example2] = explode(" + ", $a[example]);
shuffle($a[example2]);
$a[example3] = implode(" + ", $a[example2]);
$a[example4] = str_replace(" + ", ' </a> <a href=\"/folder/$a[filename]\"> ', $a[example3]);
I hope it makes sense what I'm trying to do. Everything else works, I've checked the output for every line up until the last one - it just won't put out the link ...
<?
$a[term] = 'widget';
$row[example_string] = 'red,blue,green';$a[filename] = strtolower($a[term]);
$a[example] = str_replace(",", ' + ', $row[example_string]);
$a[example2] = explode(" + ", $a[example]);
shuffle($a[example2]);
$a[example3] = implode(" + ", $a[example2]);
$a[example4] = sprintf('<a href="/folder/%s">%s </a>',$a[filename],str_replace(" + ", " </a> <a href=\"/folder/$a[filename]\"> ", $a[example3]));
echo "<pre>";
print_r($a);
?>
baze
<?
$a[term] = 'widget';
$row[example_string] = 'red,blue,green';$a[filename] = '/folder/' . strtolower($a[term]);
$a[example] = str_replace(",", ' + ', $row[example_string]);
$a[example2] = explode(" + ", $a[example]);
shuffle($a[example2]);
foreach ($a[example2] as $key=>$val) {
$a[example4] .= sprintf('<a href="%s">%s </a> ',$a[filename],$val);
}
echo "<pre>";
print_r($a);
?>
Also unless you are expecting '+'s in your string, you could skip the ',' replace and just explode using ',' right into $a[example2].
baze
$a[example4] = str_replace(" + ", ' </a> <a href=\"/folder/$a[filename]\"> ', $a[example3]);
Then I am guessing you get something except the link doesn't have a url in the href attribute. If this is the case its because you have used single quotes around the second argument in the str_replace() function. There is no variable interpolation when using single quotes, or in other words it wont get the value of $a[filename], it will just print out $a[filename] as a string of text.
You could therefore try changing it to:
$a[example4] = str_replace(" + ", ' </a> <a href="/folder/'.$a[filename].'"> ', $a[example3]);
There is no variable interpolation when using single quotes, or in other words it wont get the value of $a[filename], it will just print out $a[filename] as a string of text.You could therefore try changing it to:
$a[example4] = str_replace(" + ", ' </a> <a href="/folder/'.$a[filename].'"> ', $a[example3]);
Thanks. Meant to mention that, but I got so wrapped up in the rest I just fixed it and forgot about it. :)
baze
This is a little OT, but consider calling srand(), like srand(mktime()), before shuffle() in order to seed the randomizer.
True only if your version is prior to 4.2.0. From the docs:
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
baze