Me and several friends taking the same programming course have been confused by this for hours so far, hopefully someone here can help. The aim is to take a list of urls, split by new lines, prepend [ img] and append [/ img] for each URL, as suitable for a bulletin board. The actual code includes a switch to allow for both [ img] and [ thumb] bbcodes, but both have the same effect. Instead of outputting
[ img]1[/ img]
[ img]2[/ img]
it outputs
[ img]1
2[ /img]
The same happens for any number of URLs. Here's the code I am using.
<?php
$url_f = (isset($_POST['text'])) ? $_POST['text'] : false;
$thumb = (isset($_POST['type'])) ? $_POST['type'] : false;
$urls = ($url_f) ? explode('\n',$url_f) : '';
?>
<textarea rows='20' cols='40' readonly='1'>
<?php
switch ($thumb){
case 'img':
for ($i = count($urls)-1; $i >= 0; $i--)
{
echo "[img]". $urls[$i] ."[/img]\n";
}
break;
default:
break;
case 'thumb':
for ($i = count($urls)-1; $i >= 0; $i--)
{
echo '[thumb]'. $urls[$i] ."[/thumb]\n";
}
break;
}
?>
</textarea>
defaultshould come last you know, otherwise it will skip anything beyond it.