TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,234
  • Total Topics: 21,353
  • Online today: 639
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

echo an array

Started by Thalov, October 14, 2007, 04:10:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jacortina

Doesn't matter. WIth only a single member, the 'glue' string is NOT included. It's only there as a 'connector' between multiple array members.

You might need to check if the parameter passed in IS an array (using the aptly named is_array() function). You'd have to determine whether that's going to happen (but allowing for it is pretty safe). Somthing like:

function reveal($input) {
if(empty($input))
return array();

if (is_array($input)) {
$string = implode('???', $input); }
else {
$string = $input; }

$string = str_replace(array('<R>', '</R>'), array('<r>', '</r>'), $string);


Replacing the '? ? ?' with the character or string of your choice, of course.

Thalov

The $background variable is a string when it gets passed in to the reveal function. When it comes out it ends up as an array.

With the way that the current reveal function is setup...
function reveal($string) {
if(empty($string))
return array();

$string = str_replace(array('<R>', '</R>'), array('<r>', '</r>'), $string);
if(strpos($string, '<r>') === false || strpos($string, '</r>') === false)
return array();

preg_match_all("~<r>(.*)</r>~Us", $string, $output);
return $output[1];
}


Wouldn't it make more sense to put the implode after the preg_match_all function? Basically, grab $output[1] and run it through the implode function, then return that value.

jacortina

Yes, you're right. It's always one consolidated string passed in.

And it's the regular expression match which results in an array.

Except it looks like the function is SUPPOSED to return an array (or why the "return array()" statements?).

But if $output is an array result which you want to consolidate into a string to be returned, then "return implode('?/?', $output);"

Thalov

That did it! Thanks a lot JA!

This website is proudly hosted on Crocweb Cloud Website Hosting.