PHP - Convert Array To String
<?php $srs = array(); for ($section = 1; $section < 5; $section++) { for ($row = $section; $row < 10; $row++) { for ($seat = $row; $seat < 20; $seat++) { $srs[] = array( 'section_name' => $section, 'row_name' => $row, 'seat_name' => $seat); } } } output(convert_array($srs)); // Converts the array function convert_array($input) { return $input; } function output($obj) { echo "<pre>"; print_r($obj); echo "</pre>"; die; } ?>
I'm trying to convert those array number to string, add implode() to make it happen, but seem PHP didn't recognize variable in $input. Like this implode("Section: ", $input) or (Section: ", $srs). Can you help me? Thanks, Gary Edited October 16, 2019 by sigmahokiesSimilar TutorialsHi everybody, I need some help about how to convert string to array name. I have the following function which pass $_REQUEST type as parameter. It is not working because I don't know how to convert $method to $_GET or $_POST in a proper way. Do anybody know how? Code: [Select] function validateIfFilled($method, $fields) { $exploded=explode(",",$fields); foreach($exploded as $field){ if(empty($method[trim($field)])){ return false; } } return true; }; if(!validateIfFilled('$_GET', "email, password, address")) ... Thank you! How can i convert an array of results to a single comma separated string so that I can run it through an SQL query? I have a form that submits G How can I convert this to string of time when I need to insert it into the database and then turn it back around when it needs to be read? <option>11:00 AM</option> <option>11:30 AM</option> <option>12:00 PM</option> <option>12:30 PM</option> <option>1:00 PM</option> <option>1:30 PM</option> Thank you. how can i convert string type into integer like when using parseInt in javascript...however i use (int)$string but not working i have this $string1="10"; $string2="5"; and i wish to add both string ....using (int) still treat $string1 and $string2 as string so i get 105 as a result instead of 15 //$value1 = $_POST['game']; $value1 = "game7h"; if (strpos($value1, 'a')) { $team = 'a'; }elseif (strpos($value1, 'h')) { $team = 'h'; } if (strpos($value1, '7')) { $num = '7'; } elseif (strpos($value1, '8')) { $num = '8'; } elseif (strpos($value1, '9')) { $num = '9'; } $gm7hodds = $games[41]["BP"]; $gm7aodds = $games[40]["BP"]; $gm8hodds = $games[47]["BP"]; $gm8aodds = $games[46]["BP"]; $gm9hodds = $games[53]["BP"]; $gm9aodds = $games[52]["BP"]; /* $getratio = $num + $team; echo $getratio; Team is not a math operation so I'll finesse that later. */ $findratio = 'gm' . $num . 'h' . 'odds'; echo $findratio; gm7hodds How would I add the $ to it and return its array value $gm7hodds? Solved whoops -> echo eval('return $'. $findratio. ';'); Edited April 28 by Minzersolved I have ip_addresses stored in the database as unsigned integers. I want to display them in standard xxx.xxx.xxx.xxx format in a table. In my code, I tried the following: <?php while ($row = $query->fetch()) { $address = inet_ntoa($row['IP_ADDRESS']); //Throws error here echo "<tr>"; // echo "<td>" . $row['IP_ADDRESS'] ."</td>"; echo "<td>" . $row['$address'] ."</td>"; echo "<td>" . $row['FILENAME'] ."</td>"; echo "<td>" . $row['country'] . "</td>"; echo "<td>" . $row['area'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "</tr>"; } ?> It throws the following error: Parse error: syntax error, unexpected 'inet_ntoa' (T_STRING) in /home/larry/web/test/public_html/report1.php on line 205 How do I do the conversion so I can display the ip_address? Thanks in advance, Larry
I have a simple form and need to convert it to XML so I can send it to my payment gateway. I have the XML data types (?) they are expecting, but do not have a clue of how to build the string. Can someone help me out? Thanks, Debbie Hi, Sorry, me again! Ok, so i've got my url: http://www.mydomain.com/?ec3_after=2010-08-01&ec3_before=2010-08-07 I've then got the following code to get the values: $afterDateParts = split("-", $_GET['ec3_after']); $after = $afterDateParts[2] . " " . $afterDateParts[1] . " " . $afterDateParts[0]; echo $after; which returns: 01 08 2010 (correct for this demo) I've then got this to convert the above into a nicer format: $convertMe = strtotime($after); echo date('d-M-Y', $convertMe); But it always returns: 01 Jan 1970 For the love of god, I cannot work out why. Is it really not that simple? Please someone put me out my misery. I'm loosing hair by the minute! Lol TIA I got a response from an api in json. How do i echo out the account_name in string. Thanks as usual. The response is below...
{ "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } } "status": true, "message": "Account number resolved", "data": { "account_number": "2067483918", "account_name": "BABALOLA MAYOWA ABEL", "bank_id": 18 } }
Code: [Select] <?php $myServer = "202.138.125.155"; $myUser = "micro_fms"; $myPass = "micro_fms*#$"; $myDB = "micro_fms"; //create an instance of the ADO connection object $conn = new COM("ADODB.Connection")or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER='SQLOLEDB'; SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; //Open the connection to the database $conn->open($connStr); //$table_name=$_GET['Device']; $table_data=$_GET['Data']; $data=(explode(",",$table_data)); $table_name=$data[0]; $speed=$data[1]; $time=$data[2]; $date=$data[3]; $lat=$data[4]; $long=$data[5]; //$newdate = substr($date,6,2) . "-" . substr($date,0,2) . "-" substr($date,3,2); $datetime=$date.$time; $new_lat = substr($lat,0,2).'.'.substr($lat,2); $new_long = substr($long,0,2).'.'.substr($long,2); echo $table_name."<br>"; echo $speed."<br>"; echo $new_lat."<br>"; echo $new_long."<br>"; echo $datetime."<br>"; $query="insert into $table_name (DeviceNumber,Speed,dtDateTime,Latitude,Longitude)values('$table_name','$speed','$datetime','$new_lat','$new_long')"; //execute the SQL statement and return records $rs = $conn->execute($query); if($rs) { echo 'Values Inserted'; } else { echo "faile"; } ?> Hi friends... I have two variables ($date and $time). I concat these two strings and make a new variable called "$datetime". Now in above code I want to insert it into table but I got the following error. Code: [Select] Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for SQL Server<br/><b>Description:</b> Conversion failed when converting datetime from character string.' in C:\wamp\www\FMS\fms.php:44 Stack trace: #0 C:\wamp\www\FMS\fms.php(44): com->execute('insert into A00...') #1 {main} thrown in C:\wamp\www\FMS\fms.php on line 44 In my database, data type of column in which I want to insert is Date time stamp though I have string type ($datetime) variable. I think I have to convert this $datetime variable string to "DateTime type first but don't have any idea about it. Please help??/ Thanks in advance.... I'm hitting a SQL Server db and every table has a ts (timestamp) field that is a binary datatype - 8 bytes. Is there a way to "read" the binary and output it as a string? Well the topic may not sound very explicit. So I'll do my best to explain it here. I have a pull down menu as part of a form, which contains the months of the year. I'm trying to store the value of this form entry using the $_POST['month'] variable into a database but first, I need to convert the month values into their corresponding integer values( that is 1 for January, 2 for February etc), in order to easily do date calculations later down the road. Any ideas about how to do this? It may be helpful to include the code for the pull down menu. Code: [Select] <p><tab> Date of Birth: <?php //Make the month pull down menu. //Array to store months. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name= "month">'; foreach ($months as $key => $value) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; ?> </tab> <tab> <?php //Make the day pull down menu print '<select name= "day">'; for ($day = 1; $day <= 31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; ?> </tab> <tab><?php //Make the year pull down menu print '<select name= "year">'; $start_year = date('Y'); for ($y = ($start_year - 18); $y >= 1900; $y--) { print "\n<option value=\"$y\">$y</option>"; } print '</select>'; ?> </tab> </p> Hello, i have the code below and i need to have all results in a variable as a string, inside the loop they are displayed how i want but outside will echo the last result. Thank You. Code: [Select] foreach($_POST as $key=>$value){ if (is_numeric($value)) { $valoare = "$value,"; } } echo $valoare; I have this form:
<form method="get"> I have this php file which i use to get downloaded and uploaded data usage from my splynx radius server over API which outputs it as bytes making a very long string which i want to shorten into Mbps and from the arrays that i get from splynx server i would like help to convert the array "in_bytes" and "out_bytes" to MB. This is my whole code below. currently the output is in bytes and i need it to be in MB <?php $api_url = 'https://xxx/'; // Splynx URL $admin_login = "xxx"; // administrator login $admin_password = "xxx"; // administrator password $api = new SplynxAPI($api_url); $api->setVersion(SplynxApi::API_VERSION_2); $isAuthorized = $api->login([ 'auth_type' => SplynxApi::AUTH_TYPE_ADMIN, 'login' => $admin_login, 'password' => $admin_password, ]); if (!$isAuthorized) { exit("Authorization failed!\n"); } $customerApiUrl_online = "admin/customers/customers-online"; $customers_params = [ 'main_attributes' => [ 'status' => ['IN', ['active', 'blocked']] ]]; $result_online = $api->api_call_get($customerApiUrl_online); $customers_online = $api->response; ?> <table class="table table-transparent"> <thead> <tr> <th>DOWNOAD</th> <th>UPLOAD</th> </tr> </thead> <tbody> <?php foreach($customers_online as $item) :?> <tr> <td><?php echo $item['in_bytes']; ?></td> <td><?php echo $item['out_bytes']; ?></td> </tr> <?php endforeach;?> </tbody> </table>
I wish to access the following chart by the number and the headings names. field text mysqlfield 1 username Please enter a username un 2 name Please enter you name nm 3 age Please enter your age ag 4 town What town do you live in tw 5 postcode What is your postcode pc I place the field and the text in to a form and use the mysqlfield to placce the data in the mysql database. what i do not know is how to store the array data and how to access it. this is my solution:
$x = ['a' => 2, 'b' => 1, 'c' => 4, 'd' => 1]; $x1 = array_keys($x); $x2 = array_values($x); $z = []; for ($i=0; $i<count($x); $i++) { array_push($z, [$x1[$i],$x2[$i]] ); } print_r($z); //[['a', 2], ['b', 1], ['c', 4], ['d', 1]];is there easier (more elegant) way to do the same ? Hi guys! I need some help with a code problem. I've a form with 2 inputs, one single and one multiline, and I need to pass the value of both into an array, var1 (single input) is the same for every line and var2 (multiline) change with every line Hoe can i do it? |