PHP - Print_r Automatically Echos Contents
Hey guys it's been a long time, but I am back with php!
Anyway here's my dilemma: test.php <?php <?php $name = array('Chris', 'Bob', 'Jack'); $names = print_r($name); ?> Simple enough right? Well although I am not printing/echoing these results to screen it does it automatically. Meaning when I point my browser to test.php it outputs this: Code: [Select] Array ( [0] => Chris [1] => Bob [2] => Jack ) Rather than only assigning the value to the $names variable, which is what I would expect it to do. Is this normal behaviour or is there something I can change on php.ini? Thank you! Similar TutorialsI've got a few hours in this, read the manual on return (and it appears my print_r should be working!).. And I am unable to get print_r() to output the contents of my function array. What am I doing wrong? function getStateName() { $stateName = array("Alabama","Florida","Nevada"); return $stateName; } echo "<pre>"; echo print_r($stateName); echo "</pre>"; ok my code is below but i want to count how many $sname or ['member_name'] there is as if there is 4 or more i want it to add a marquee to it have that sorted but im having trouble getting it to count can you help me? $query = "SELECT * FROM `ibf_members` WHERE member_group_id = '4' or member_group_id = '6' or member_group_id = '17' or member_group_id = '18' or mgroup_others = '4' or mgroup_others = '6' or mgroup_others = '17' or mgroup_others = '18' "; $result99 = mysql_db_query("pbf99_backup", $query); $staff1 = mysql_num_rows($result99); if ($result99) { while ($r = mysql_fetch_array($result99)) { // Begin while $sid = $r["member_id"]; $smgid = $r["member_group_id"]; $query2 = "SELECT * FROM `ibf_sessions` WHERE member_id = '$sid'"; $result2 = mysql_db_query("pbf99_backup", $query2); if ($result2) { while ($r2 = mysql_fetch_array($result2)) { // Begin while $sname = $r2["member_name"]; $query3 = "SELECT * FROM `ibf_groups` where g_id = '$smgid'"; $result3 = mysql_db_query("pbf99_backup", $query3); if ($result3) { while ($r3 = mysql_fetch_array($result3)) { // Begin while $ssuffix = $r3["suffix"]; $sprefix = $r3["prefix"]; echo "<a href='$host$sid' target='_parent'>$sprefix$sname$ssuffix$stafff</a><br><br>"; }}}}}} ?> I'm pulling 10 records here. How do I split the results in to several echos? $query = "SELECT statez, COUNT(statez)FROM mylist GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> I need the code to look like this by showing the (COUNT) number for each state. $results = mysql_query($query); while($line = mysql_fetch_array($results)) { echo $line["number_in_state1"].",,"; echo $line["number_in_state2"].",,"; echo $line["number_in_statee3"].",,"; echo $line["number_in_state4"].",,"; echo $line["number_in_state5"].",,"; echo $line["number_in_state6"].",,"; //etc.... } I'm trying to make it so that if the $row data is more than just "" (empty) then echo if not then run the scan on the next number. It just keeps repeating the values all the way through? Help? Thanks. function scan($random) { if ($random == 1) { $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(2); } } if ($random == 2) { $query = "SELECT * FROM users WHERE clicks > 10 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(3); } } if ($random == 3 OR 4 OR 5) { $query = "SELECT * FROM users WHERE clicks > 0 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } } $random = rand(1, 5); scan($random); I have a problem with formating the appearance of a die statement. As you will see from the css below, p.form and p.passed both have the same text-align, and marginal values, however they display very differently. P.passed is used in an echo, and P.form is used in a die. I want to display both my echo and die statements in the same place. Ive tried the obvious and played around with the margins on P.form but it doesnt seem to make any difference. I can only presume that my die statement is ignoring the class im assigning it? P.form { color:#FF03; margin-left:100px; text-align:left; clear:both; } P.passed { color:#333; margin-left:100px; text-align:left; clear:both; } Code: [Select] <?php // snippet if($Name == '') { die ("<P class=\"form\">You did not complete the name field, please try again</p>"); } elseif ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone))) { die('<P class="form"> You completed the telephone field incorrectly, please try again</p>'); } elseif ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL))) { die('<P class="form"> You completed the Email field incorrectly, please try again</p>'); } elseif ($Postcode == '' or (!checkPostcode($Postcode))) { die('<P class="form"> You did not complete the Postcode field correctly, please try again</p>'); } elseif ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website))) { die('<P class="form">You completed the website field incorrectly, please try again</p>'); } else { echo("<P class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>"); }} Ive formatted if and else slightly differently but the output is still the same. Should die statements and echo's display differently? How come my$_SERVER['PHP_SELF'] echos the filename.php I have a rewrite rule and i need it to echo http://site.com/file/321 instead of filename.php?id=321 Help! Godaddy wont tell me why its doing that Hi, all... have a basic question here as a newbie that I am... Many times, in some scripts I see (I think, if not mistaken), places where within a echo sentence I see variables echoed like this with no quotes: echo "First Name: $firstName and Last Name: $lastName"; as opposed to like one would expect: echo "First Name: " . $firstName . " and Last Name: " . $lastName"; Sometimes I see that also when variables are used in select/update statements I think.. like this: $query = mysql_query("SELECT FROM table WHERE column = $columnname"); Instead of like this within quotes: $query = mysql_query("SELECT FROM table WHERE column = '$columnname'"); Is it because some of these values may be numbers (numeric) as opposed to "strings"?? Not sure if I make sense... appreciate teh feedback, Thanks! <?php error_reporting(0); $numm0 = array(1,2,3,4,5,6); $numm1 = array(1,3,4,5,6); $numm2 = array(1,2,3,4,6); $numm3 = array(1,2,3,5,6); for($i = 0;$i < 4;$i++) { print_r($numm.$i); } for($i = 0;$i < 4;$i++) { $w.$i = array_sum($numm.$i); print_r($w.$i); echo "<br>"; } ?> this code just hangs when executed. how can the syntax of the print_r() function and array_sum() function be modified? need help... Here's the result of my problem: Array ( [nav_create_title] => hel [nav_visible] => 1 [category_position] => 4 ) ( ! ) Notice: Undefined index: category_postion in C:\wamp\www\tryitandbuyit\includes\category_create_process.php on line 7 Call Stack # Time Memory Function Location 1 0.0010 370336 {main}( ) ..\category_create_process.php:0 Here's how I'm trying to assign and echo $_post. print_r($_POST); $category_pos = $_POST["category_postion"]; $nav_title=$_POST["nav_create_title"]; $nav_visible=$_POST["nav_visible"]; echo $nav_title; echo $category_pos; echo $nav_visible; As you can see, it prints the correct value and name from the array... why the heck can't I assign or echo it? Here is how I am sending it from the other page in a form (it used to be simple, but I've been trying every work around i can think of: <?php $result=mysql_query("SELECT * FROM category WHERE visible='1' ORDER BY position ASC"); $row=mysql_fetch_array($result); $positionID=$row['position']; $position=$row['position']; $selectname= "Select A Position:<br />"; $selectname .= "<select name="; $selectname .= "'category_position'"; $selectname .= ">"; echo $selectname; $rownumber=mysql_num_rows($result); $rownumber_temp=$rownumber+1; For($i=1; $i<=$rownumber_temp; $i++) { echo "<option value= $i>" . $i . "</option></br>"; } $selectname2 = "echo \"<br />\""; $selectname2 .= "echo \"<br />\""; $selectname2 .= "echo \"</select>"; echo $selectname2; I am working on modifying some code and wanted to check some variables, but am stuck on something that is probably simple, just over my head. If I do the following: print_r ($this); I get this result (I used PRE tags to format it) ViewList Object ( [_name] => list [_models] => Array ( => ModelList Object ( [_data] => Array ( => stdClass Object ( [id] => 70 [catid] => 1 etc...... Moving down, I typed this... print_r ($this->_models); and get this... Array ( => ModelList Object ( [_data] => Array ( => stdClass Object ( [id] => 70 [catid] => 1 How would I get, for instance, the id? If I try print_r($this->_models->list); nothing happens. In other words, if I wanted to return the id, what would it be -- $this->_models->??? . I tried all kinds of combination's and other ways to do it, just can't figure it out. I know it is my limited knowledge with PHP , so could someone point me in the right direction. Thanks, Doc [/list][/list] After switching from PHP 5.3 on Windows Server 2003 to PHP 7.4.3 on Linux Mint 19.3 (Tricia Cinnamon), I find that the output of print_r() has changed. If we look at the documentation (https://www.php.net/manual/en/function.print-r.php), the provided example output is as it was on my earlier machine: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) ) </pre> However, on the second machine, the output is: <pre> Array ( [a] => apple [b] => banana [c] => Array ( [0] => x [1] => y [2] => z ) <blank line> ) </pre> Note the unexpected new line after each recursed array's closing parenthesis. The new line is not present after the outermost array closing parenthesis. Also to note, there is a newer version of XDebug installed. My question is: Is this a bug? (Follow-on question: if possible to determine at which version the output changed, what version would that be?) This difference is causing existing code to not be able to correctly parse that output. Hey Is there a way to trim the print_r($array); so its completed and void of white space? It prints like this: Code: [Select] Array ( [0] => Array ( [id] => 10 [f] => data/tiles/image.png ) ) But I want it to be compressed like this: Code: [Select] Array([0]=>Array([id]=>10[f]=>data/tiles/image.png)) This is then to be stored in the database, so any compressed possible is a plus in this situation. Any ideas? i have checkboxes on the database page and if checked they send to the shopping basket i have the items selected to display but like this
Array ( [0] => Imagine DragonsImagine DragonsRockI Bet My LifeKIDinaKORNER1.25Brand new single from the incredible Imagine Dragons )
So I have been printing out some debug information, and now I am trying to instead save it to a string, which I will print out at the end of the page. Here is some specific problematic code: $myplugin_debug_test.= "\n[GETTING COOKIES...\n"; $myplugin_debug_test.= print_r($myplugin_all_cookies);//THIS IS LINE 38 $myplugin_debug_test.= "\n... DONE]<br/>\n"; However, when I do this I get the following error: Quote Warning: Cannot modify header information - headers already sent by (output started at ...:38 So my question is how can I output the array data into a string, so that I can print it out later. Like what am I doing wrong? Is there a better way to do this? Thanks! the array is getting the values as he should get and from there i send them to $temp (string),but when i'm trying to print them i can't. the array and the string at the end of code saved the values that the code gave them,but i can print the values one by one, but i need the values in string and the array at the end and print $temp(string) in a row without white space. print_r is working but she's not build to this job can someone look at the code and the result of the code and tell me what seem to be the problem and how to fix that? the problem start with $txt when the array is getting the values. the output of this code:http://pastebin.com/0QkzjviW the code page is attach to this message as php file. Hi, I was wondering if it is possible to have the foreign keys (FK) to automatically assign its value to the corresponding PK (primary key) it references? Let's say I have four tables (with their PK,FK and other fields) Code: [Select] TABLE document: TABLE pathway: TABLE leaf TABLE value: PK: docID PK:pathID PK:leafID PK:valueID filePath pathway FK:pathID FK:leafID fileName FK:docID value target source So when I upload a document, it is added to TABLE document, where PK docID set, and at same time I would add the filepath to TABLE pathway, and now I want TABLE leaf's FK to AUTOMATICALLY add the pathID, docID and ALSO at same time TABLE value's FK of leafID will also be added for that ONE entry that was initally added to TABLE document, pathway. Please I hope someone understand what I want to do, I know FK is for ensuring integrity of data. Please any help is appreciated. Please use my example to help me, thanks. PS: I know the formatting is off which I noticed when I went to preview the post, sorry. Hello friends, In this topic i am getting confuse, and never know how to do work. My problem is that: 1>> I want to send SMS, by PHP pages to mobile. 2>> If user write some Quotation into the calender date, then automatically SMS send to all of those friend with the quatation metter. 3>> All work is store also in MYSQL database also. So please tell me what I do in this case because over the internet only SMS sending code is available, but automatically sms sending option is not given. Please help me then i do this job easily. Thanks Hello, I am new here but I hope you can help me with a problem that I've been stuck with for days. I am trying to populate the content of a website through XML files (zipped) that are located on an FTP server. I managed to get the zip file but I'm not sure if it is the correct way: Code: [Select] function ftp_copy($file) { $conn_id = ftp_connect($ftp_host) or die ("Can't connect"); $ftp_login= ftp_login($conn_id, $ftp_user, $ftp_pass) or die ("Can't login"); ftp_pasv($conn_id, true); ftp_chdir($conn_id, "/zip_files/"); return ftp_get($conn_id, $file, $file, FTP_BINARY); } ftp_copy('1001.zip'); After that I will need to extract the zip file. I'm planning to use pclzip library for it and save the contents on a database. Also this has to happen everyday so I'm thinking about using a cron job, although hourly is also preferable since the XML files could be generated more than once per day. Am I doing it the right way or is there a better solution for this? Any help will me much appreciated! Thanks a lot! Hi Guys, I have the following $pattern = '<tr class="newsitem">'; when I echo this out it produces <tr class="newsitem"> </tr> Why is it automatically closing the tag? I dont want this becuase i'm using preg_replace and the tag is closed elsewhere already on the page. |