Page 1 of 1
functions within print or echo
Posted: Fri Apr 25, 2003 8:18 pm
by wallabee
is this possible? for instance:
Code: Select all
print("<textarea name="textarea$file" cols="40" rows="8">FillTextArea()</textarea>");
FillTextArea takes the text from a text file and simply fills the text area with said text (and suddenly my two recent posts seem to connect).
-ben
Posted: Fri Apr 25, 2003 8:37 pm
by m3mn0n
did you run it yet?
Posted: Fri Apr 25, 2003 8:43 pm
by wallabee
it just puts, verbose, the words FillTextArea() in the text area.
Posted: Fri Apr 25, 2003 8:47 pm
by m3mn0n
hmm..
Posted: Fri Apr 25, 2003 10:05 pm
by airo
or split t up into three echos. Techniquelly there is a way to do it in one line, but it gets alittle messy that way, and i prefer to split it up into 3 echos.
Posted: Fri Apr 25, 2003 10:11 pm
by phice
Code: Select all
<?php
function your_function() {
$string = "your displayed text";
return $string;
}
echo "Our function returns: " . your_function . "<br /><br />\n";
?>
Posted: Sat Apr 26, 2003 5:27 am
by twigletmac
Slight alteration to Phice's code (don't forget the parenthesis on the function name):
Code: Select all
echo "Our function returns: " . your_function() . "<br /><br />\n";
Posted: Sat Apr 26, 2003 5:31 am
by twigletmac
wallebee - with your code you can do:
Code: Select all
print '<textarea name="textarea'.$file.'" cols="40" rows="8">'.FillTextArea().'</textarea>';
or, if you want double quotes around it
Code: Select all
print "<textarea name="textarea$file" cols="40" rows="8">".FillTextArea()."</textarea>";
Not a big fan of escaping attribute quotes myself but some people don't like having to concenate in their variables... General principle is the same though - you have to leave the string to run the function and then return to it after to add the rest of it.
Mac
Posted: Sat Apr 26, 2003 7:03 am
by []InTeR[]
I'm a old C programmer, so correct all the programmers i'm working with to use quotes as they sould.
The ' is for char's. Not for strings.
The " is for strings.
And if a user has something like
i correct it to
Just make it more readable and understeadable for the progammer and the program.
Posted: Sat Apr 26, 2003 7:15 am
by twigletmac
But in PHP, stuff in single quotes isn't parsed so this:
would make more sense than
in that you wouldn't be making unecessary work for the parser.
Mac
Posted: Sat Apr 26, 2003 7:18 am
by []InTeR[]
There is a differents?
So your say'ing that the ' things are faster to compile for php then " ?
Learned something, and that in the weekeind

Posted: Sat Apr 26, 2003 7:36 am
by twigletmac
[]InTeR[] wrote:There is a differents?
Yup, check out:
http://uk.php.net/manual/en/language.types.string.php
[]InTeR[] wrote:So your say'ing that the ' things are faster to compile for php then " ?
probably won't make too much of a difference in small scripts but is more efficient.
Mac
Posted: Sat Apr 26, 2003 9:00 am
by volka
and since today's topic if efficiency:
doesn't even waste time and memory for string concatenations.
btw:
<smartass>
- it's not that much about compile but runtime efficiency.the substitution takes place the moment the statement is executed.
</smartass>

Posted: Sat Apr 26, 2003 10:43 am
by airo
I never knew there was a diffrence between ' and "... thanks mac!