Assign Function Output To Variable??
I've found some references to this topic at :
http://forums.devshed.com/showthrea...ion+to+variable
but it does not seem to be working for me.
here's a snippet...
<? PHP
function listPeople ($getArray)
{
foreach ( $getArray as $val )
{
echo "$val, ";
}
}
$foo = listPeople($splitDirector);
?>
The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.
View Complete Forum Thread with Replies
Related Forum Messages:
Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ??? eg. <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> <? if (db_num_rows($qid_p) == 0) { ?> <li>No <? } ?> <? while ($prod = db_fetch_object($qid_p)) { ?> <p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b> <br><? pv($prod->description) ?> <br>$<? pv($prod->price) ?> <br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>] <? } ?> How to assign this code to a unique variable ???
View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
View Replies !
Capturing Print Output Of Function To Variable
I have a function, say: function printTable($Variables) { ?> <table> <tr><td>Your name is</td></tr> <tr><td> <?php print $Name; print "</td></tr></table>"; } (Obviously not my exact function, but a simple one to demonstrate my needs... The function I have inherited is much bigger with much mixed php and html like the example) It is currently used to print the same data table on many pages. I have been asked to have the system send this data table by email, so what I want to do is run the function, but send the output of the function to a variable, in the same way that print_r($arr,1) will return the output instead of printing it.
View Replies !
Assign Value To Variable
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering if a function exists where I can pass a variable name and a value, and the variable would be created. ie. somefunc("sn", "Shore") Would create the variable $sn and assign the value "Shore" to it.
View Replies !
Assign To Variable
I am trying to take data from the database and assign it to a variable but i'm not sure how this is the code ive been trying $sql = "SELECT Name FROM Names WHERE Name = 'Peter'"; while($row = @mysql_fetch_array($sql)) { $var == $row['Name']; }
View Replies !
Ways To Assign A Value To A Session Variable.
I am wandering which way to assign a value to a session variable exist. Which of the following examples will work. Example #1: session_start(); session_register("ex"); $ex = 2.0; Example #2: In first.php: session_start(); session_register("ex"); In second.php: $ex = 2.0; Example #3: In first.php: session_start();...
View Replies !
Assign Variable From Database Field
Is there a way to assign a variable from a database field? I'm thinking along the lines of $make = $row_rsList['make']; $model = $row_rsList['model']; then they'll switch out based on my SQL WHERE statement. This valid syntax?
View Replies !
Assign Userid To A Session Variable
When a user logs into my system, i assign their userid to a session variable [php] $_SESSION['userid'] = $myrow[0]; [php] and then a user logs out, i do the following [php] $_SESSION['userid'] = '' session_write_close(); [php] so, when a user clicks on a link to a page they should only see when logged in, i do the following test [php] if (isset($_SESSION['userid'])) { header('Location: members.php3'); } [php] but the logout does not seem to work for some reason? userid still seems to be set after running the logout script, any ideas? am i doing something silly?
View Replies !
Assign Function To Class....
Is it possible to assign some functions to a of a class? class loginClass { function initialize() {$something} } function CheckLogin() { $something } $login = new loginClass(); $login->onLogin = CheckLogin(); $login->initialize(); where the CheckLogin function will only be run during the initialize of the class, not during loading of the whole document.
View Replies !
Assign A New Value To A Variable Passed From An Html Form
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3. if ($question3!="select days") { $question2=$question2+$question3; } This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.
View Replies !
Multi-Dimensional Arrays - Assign Variable
It's a simple question, but I'm just not getting it. I have two files: <?php $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc... <?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc... I want to assign the value of "2324" to the variable $number. I've done this with arrays that start with number=>1, 2, 3, etc., but not successfully with specific values. What am I missing?
View Replies !
Assign Variable To A Block Of Html Code
Is it possible to assign variable to a block of html code? Something like this : $myblokvar = "<table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="images/bartitle_login.gif " alt="Login" width="475"...
View Replies !
Assign Variable Name As Variable
I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable. For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop. Code:
View Replies !
Extract Variable From Database, Then Output That Variable.
I have this strange problem (and probably also a strange question). Let's say you set a variable $blah. The variable has 'test' as content. When I write the variable ($blah) to a database (and not the content of the variable 'test') and I want to output the variable again, I get $blah as output. And not 'test'. PHP Code:
View Replies !
Output A $variable
Hello lovely helpful people, i need to out put: $src = array( dynamically and am having a problem when you use this echo("$src = array("); the $src is seen as a variable itself and so not echoed as it is empty, how can i get round this.
View Replies !
Variable In DB Output
I'm pulling HTML from a DB and would like it to respond to variables from the outside. Say I have this in my MySQL field: <?=$name?> $name = "Jack"; $rq = $db->query("SELECT * from greetings WHERE `id` = '$gid'"); while ($r = $db->fetch_array($rq)) { echo $r['greeting']; }
View Replies !
Output From A For Loop Into One Variable
I know the answer to my question may be quite obvoius, one of those days I guess. The kind of day that me and me head is not running on all cylinders. The question: How do you take an output from a for loop and place it in variable to echo.
View Replies !
Include Output As Variable
I'm working with some code, and have run into an issue that, after a long search on the forums, I still haven't located a resolution to. I'm familiar with includes, and have used them quite a bit with the last several webpages I've designed. However, currently I have data from an external source that I can add as an include file (the output is a text string) but the location I need to add this data is inside a variable string. As an example : PHP Code: $display_content = " <tr> <td>blah blah</td> </tr> <tr> <td> [NEED INCLUDE DATA HERE] </td> </tr> <tr> <td>blah blah</td> </tr>"; ..........................
View Replies !
Can't Output A Variable To HTML
I have this code on a page: <p class="appTitle"> <?php echo "$appTitle"; ?> </p> But the resulting HTML is: <p class="appTitle"> </p> $appTitle is a global variable which I've declared at the top of the page in a require_once file like this: $_GLOBALS['appTitle'] = "My App Title"; According to my debugger, $appTitle is defined with the correct value when execution reaches that point. I've also tried, <?= "$appTitle" ?> However this work fine: <?php $appTitle = "My app"; ?> <?= $appTitle ?> I have a feeling the answer is something totally obvious, and I'm just not seeing it.
View Replies !
Streaming Output To A Variable
I am trying to find a way to stream output to a variable. Basically I have a file that mostly an html document (it does have one or two php tags) that I want to include, but I don't want it outputted, I want it put into a variable.
View Replies !
Use Stripslashes() To Get A Clean Output Of My Variable
I have begun to use mysql_real_escape_string() to prevent injection attempts. Now, and rightly so, when I echo the output backslashes are added before illegal characters such as ' and ". My question is can I safely use stripslashes() to get a clean output of my variable. I shouldn't have to worry about mysql injection at this point, but are there any other securtiy worries? I have also begun using htmlspecialchars().
View Replies !
Saving Output Of PHP File To Variable
I've got a script i wrote that is piecing together a CSV. Part of this task is to include HTML code inside of the CSV. What i'm trying to do is save the output of a file like text_file.php to a variable like $text_file_output. I can't figure out a way to include the output of a PHP page to a variable.
View Replies !
Limit Output Of A Variable (length)
Hi im scripting a site for a newspaper where I have to display a page (a category) which displays summaries to the entire articles On the category summaries page I want to show either 3 full sentences (looking for three periods) or I want to show X amount of characters in length. I have all the text stored in one variable.... whats the best way to do this?
View Replies !
Output Format For A Timestamp Date Variable
I have a variable - $lastdate - that is the latest date any record in a MySQL database was updated. Its MySQL format is TIMESTAMP. If I say [echo $lastdate] I get the output I'd expect - 20060424221549 which is a YYYYMMDDHHMMSS format. I'd like to be able to display that using a format of mm/dd/yy with no leading spaces on the month and day. I don't know what the php command is to do this. In other words, I'm trying to display a variable - $lastdate - formatted a certain way. I know that the formatting string n/j/y will get my output looking as I'd like, but I can't figure out how to apply that to my variable.
View Replies !
Capturing PERL Script Output Into PHP Variable
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br> "; print STDERR "PERL This is text sent to STDERR<br> "; $output="PERL Some output:<br> "; for ($i=0; $i<5; $i++) { print STDOUT "PERL $i: This is text sent to STDOUT<br> "; $output .= "PERL line $i of output---<br> "; } print $output; exit; ------------------------------------- passthru3.php ------------------------------------- <? $command = "/usr/local/bin/perl"; $pgm = "test3.pl"; print "PHP: Before passthru, in PHP...<br> "; $result=passthru("$command $pgm your_variable"); print "PHP: After passthru, result=($result)<br> "; ?> ------------------------------------- OUTPUT: ------------------------------------- PHP: Before passthru, in PHP... PERL Hello from Perl! (plain print) PERL 0: This is text sent to STDOUT PERL 1: This is text sent to STDOUT PERL 2: This is text sent to STDOUT PERL 3: This is text sent to STDOUT PERL 4: This is text sent to STDOUT PERL Some output: PERL line 0 of output--- PERL line 1 of output--- PERL line 2 of output--- PERL line 3 of output--- PERL line 4 of output--- PHP: After passthru, result=()
View Replies !
Load The HTML Output Of A File Into A Variable?
How can i load the html output of a file into a variable.. Kind of like include()ing or require()ing a file.. but not echoing the content.. but saving it to a variable.. Can it be done? I dont want to use fgets because they are PHP files.. and i want to get the HTML as if a user opened with a browser..
View Replies !
Adding Variable Output To An Array (beginner)
I have a variable that stores a temporary password. I'm just learning about arrays. I know this is wrong $pwList[]= ($newPW); I want to add the value of the $newPW which keeps changing to a unique variable and store each one in the array. How do I do that? Code:
View Replies !
Increase Variable Digit Output Amount
I'm working on a small script that uses polygons to find pi, and I need a way to increase the default amount of digits that are presented. Currently, each variable is displayed with 13 digits. I'd like it to be closer to 30, or higher for better accuracy. Any way to do this?
View Replies !
PHP Exec Function No Output
I am running PHP 5.1.6 (cli) on Linux. When i use the exec($cmd, $output, $return) command the $output array is always blank if the command had an error in it. There are only values if the command was successful. How do I capture the error text returned?...
View Replies !
Output Class Function To $var
I am having a bit of a problem with my first class. In general there is a function named "table" in my class that I wish to retrieve a string of info from to be passed on to fasttemplate. PHP Code:
View Replies !
Preventing Function Output Going To Browser
How do I prevent the output of a user defined function from going to the browser? In my script I do something like: $MyVar = MyFunction($var1,$var); which works, except that the output from MyFunction is sent to the browser. I simply want it to set in the variable.
View Replies !
Passing Multilevel Array To Function, Output
i am still newb at functions and classes im trying to pass a multilevel array to a function of a class, such as this.. $array1 = array("w" => "value", "x" => "value2"); $array2 = array("y" => "value3", "z" => "value4"); $search = new Search(); $search->query($array1, $array2); is that the correct way to pass an array, and how do i access the arrays, contents, and original key names (w,x,y,z) within the function currently i have something like this for my class/function Code:
View Replies !
Need Function To Output Either 1,2,3 Or 4 And Use A String As A Randomizing Factor
I have a strange-ish request so I will try and explain very carefully. I want to create a function that will return 1 digit...either 1,2,3 or 4. the function will accept one argument which is always a string. The string could be any length...probably never over 50 characters though. What the function uses the string for is as a randomizing factor in choosing whether to return 1,2,3 or 4. Code:
View Replies !
Php Function To Read Local Python Script Output, Not Code
On my server python has to run in the wwwroot/cgi-bin folder, but php can run anywhere. My site is going to be written in python but I don’t want my user to see the url as mysite/cgi-bin/... . So for example my homepage, index.php should contain a simple php script that will get my python page from the cgi-bin directory and display it. However when I try to use SSI or fopen/file_get_contents/readlink and commands like these it just displays the python code. Where as when I visit the python page in my browser it runs it and displays the output for me. My question is what php function can I use to execute my python page and return the output, not the code itself. (I think my hosting provider has disallowed certain powerful commands like system() etc. Does this make it impossible?). As the very least can’t my php script pretend to be a www user and ‘visit’ the python page to read the output?
View Replies !
Variable Scope - Function In Function
Here's something that I can't manage to find explicitly documented. In the following snippet: function outer() { global $a; function inner() { global $a; echo $a.Ƈ<br>' } $a = 's' inner(); echo $a.ƈ<br>' } outer(); ?> If either of the globals statements is removed, the variable is not accessable within inner.
View Replies !
$variable->function();
I'm going to be using this symbol a lot and I don't know what it means. I was just wondering what the arrow ($variable '->' function() means in the command above.
View Replies !
IF Function Within Variable
I am using a submission form to obviously submit a form from my website. I want to be able to control what variables are sent by using an IF function, however as I suspected, I am not having much luck. I KNOW that this code is horribly incorrect, but is there any possible way of doing what I want or will I have to use separate submit forms? PHP Code:
View Replies !
Variable Within A Function?
How do I do a variable within a variable within a function? in the code below, $client is defined in client.inf. If I express $client (as shown), which is the same as the true directory name the script doesn't work. $client=񟍳' Warning: Unable to create '/home/httpd/html//upload/img/test.jpg': No such file or directory in /home/httpd/html/0003/upload/process_upload.php on line 8 failed to copy file However, if I explicitly express $client (ex.?' as the client directory) it works fine. not using an alias under Apache, permissions are wide open during testing, and $client echos in the same script (process_upload.php4) that I receive the error message Code:
View Replies !
|