PHP - Convert String Into Already Available Variable ?
//$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 Similar TutorialsHello, 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 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.
<?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 sigmahokiesHi 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 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 Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick 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 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.... 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 } }
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'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? How can i convert an array of results to a single comma separated string so that I can run it through an SQL query? 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> I'm having trouble with a few pages on xcart with the charsets. The problem we're having is that we need to have both utf-8 and iso type charsets as we're getting garbled code on some pages. What I can do is set the utf-8 on all pages and then encode the garbled code into utf-8. Is there a function that does this in PHP or any modules I can use? Thanks Hi, I have a connection set up to an API using a PHP script - the API sends back data in JSON format, and if I capture it and echo it, it displays in extremely unfriendly format on the screen. I've tried to find a way to convert this data into readable format, ideally in a HTML table, but although there are articles on converting manually inputted JSON data into a HTML table using Javascript, I can't find a way to do it from a PHP variable. This is what I have so far: if ($_POST['getcompany']) { $companyname = $_POST['_Name']; $ch = curl_init(); $data_array2 = array( 'token' => $token ); $make_call2 = json_encode($data_array2); //echo 'Token is '.$token; $token2 = substr($token, 14); $token3 = substr($token2, 0, -3); //echo 'Token 2 is '.$token3; //echo 'Company Name is '.$companyname; //curl_setopt($ch, CURLOPT_GET, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: '.$token3.'')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'https://connectionurl?countries=GB&name='.$companyname); //Execute the request $result = curl_exec($ch); echo 'Companies: '.$result; //This displays the data provided by the search, but is in JSON format
So I need a way to get the data held in $result, into a HTML table. Any idea how I can do this?
Hello All, function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek Hi there, im trying to have a form show up when user clicks "add joke". I need the variable to be retrieved from the url query string. I cant get the form to show up. I think its either an issue with the GET function at the top or the link down at the bottom. Please help! <?php // If the user wants to add a joke $_GET['addjoke'] = $addjoke; if (isset($addjoke)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <P>Type your joke he <BR> <TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"> </FORM> <?php else: // Connect to the database server $dbcnx = @mysql_connect("servername", "username", "password"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // Select the jokes database if (! @mysql_select_db("jhodara2") ) { echo( "<P>Unable to locate the joke " . "database at this time.</P>" ); exit(); } // If a joke has been submitted, // add it to the database. $joketext = $_POST['joketext']; $submitjoke = $_POST['submitjoke']; if ("SUBMIT" == $submitjoke) { $sql = "INSERT INTO jokes SET " . "JokeText='$joketext', " . "JokeDate=CURDATE()"; if (mysql_query($sql)) { echo("<P>Your joke has been added.</P>"); } else { echo("<P>Error adding submitted joke: " . mysql_error() . "</P>"); } } echo("<P> Here are all the jokes " . "in our database: </P>"); // Request the text of all the jokes $result = mysql_query( "SELECT JokeText FROM jokes"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["JokeText"] . "</P>"); } // When clicked, this link will load this page // with the joke submission form displayed. echo("<P><A HREF='$PHP_SELF?addjoke=1'>Add a Joke!</A></P>"); endif; ?> see the problem live at http://www.freewaycreative.com/insert2.php I need to see if someone can point out something that I have missed or maybe even point me in the right direction on something. I have a PHP script that I have run into a problem on. The basic idea of the script is that it will send out HTML formatted emails to users of my web site. The problem I am running into is storing the HTML content in memory so I can do a str_replace() looking for certain markers in the HTML and replace them with lets say the users name and custom links that pertain to the particular user that the email is going to. Currently the HTML is being stored in a MySQL database, but I have already tried reading it from a flat file. Each time I only get the first 1024 characters returned. The problem seems to be that I am running into a PHP STRING limitation. From the reading that I have done on the subject, the limit should be 1024 characters PER LINE with the variable able to hold somewhere around 8MB worth of data. I can tell you that it does not matter how many \n I put into the HTML I still only get the first 1024 characters. Is there a way I can get the entire HTML file (about 12k characters) in memory so I can work with it and hand it off to the mail function? Thanks, whit3fir3 |