PHP - Problems With Encode
Similar Tutorialsi know of Bace64 rot_13 is thare more than just this? (for urls) base64_encode is a perfect standard php encoding, but this produces = most of times. Is there an alternative making the encode by alphanumeric only? Hi, I am working on a project, and my customer is demanding some sort of "non-standard" hashing to encode field values on a database. This customer wants something exclusive, difficult to be decoded, and would accept no argument proving that the existing hash algorithms are good enough for the job. What makes it even more challenging for me is that I don't have much experience in PHP. The output should be something similar to a hex triplet (web color), so... this basically means I cannot use MD5, SHA, etc. This also means that PHP hash() function is useless in this case, unless there is a hash algorithm I don't know about, and that gives me the output I need. What I need is something like: Code: [Select] $output = functionthatdoesntexist("string to be encoded"); The "$output" var should contain something like: 19f7b4 (this is just a random value I am using to illustrate the format required for the output.) Now here are my questions: 1) Is there a PHP function that encodes a string/number, and gives me back a "hex triplet"? 2) If such function doesn't exist, is there a way to create one from scratch? How should I start? I just can't figure out how to solve this problem, so any help is appreciated. Thanks in advance, AP This should be really simple but I can't get my head round it. Please see the PHP/HTML below. <?php $a = array( 'test' => "'data'" ); $json = json_encode($a); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Unknown Page</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.5.min.js"></script> <script type="text/javascript"> var j = jQuery.parseJSON('<?php echo $json; ?>'); </script> </head> <body> </body> </html> You will notice that data is stored by " then ' I have tried how it is and also with add slashes $a = array( 'test' => addslashes("'data'") ); It either outputs without slashes (which is clearly wrong) Code: [Select] var j = jQuery.parseJSON('{"test":"'data'"}');Or which I cant work out why dosent work Code: [Select] var j = jQuery.parseJSON('{"test":"\\'data\\'"}'); Now firebog throws the following error Code: [Select] missing ) after argument list How should I be escaping this variable? This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=357168.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315503.0 Hello - I am connecting to MySql and running a query. If I use a foreach loop, I can iterate over the results and have them print to screen. However, when I try the below everything is null!
How can I add the results of my MySql query to a php array?
<?php $con=mysqli_connect("site", "user", "psasswr=ord", "db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT * FROM test LIMIT 10"; $result = mysqli_query($con,$sql); echo json_encode($result); mysqli_free_result($result); mysqli_close($con); ?>
but what this prints is: {"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null} Code: [Select] echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />'; This is showing up images great in firefox, safari and chrome, but in internet explorer it shows a nice red cross, and I assume it is because of the encoding? Does anyone know how to get working in internet explorer as well? Pretty urgent job! Much appreciated for your help! Hi there. I was wondering if it were possible to convert text to numbers or some sort of URL friendly link. For example, "Hello there" would be converted to '435342553' or whatever. I want to do this because for example when someone goes to this URL, example.com/435343434, the number/uri string would be decoded and whatever the text was it would be displayed on the site. I can write all this code no bother I just need some advice/ideas on the the encoding/decoding of the text. I was looking at some options for doing this..... hexdec - removes spaces md5 - cannot be decoded? None of them seem to be working, the problem is decoding them. md5 creates a perfect uri string but as I said it cannot be decoded. I would appreciate any ideas of suggestions. Thanks a million. class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); It display a blank page like attachment result1.jpg, but if I move the $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); from function debug() and join it with function execute() like this: public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } it return me Linuxformat content ( expected result ) like result2.jpg below is the working code : class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec" First Since I first started learning PHP, I've been writing code for forms like this: $name = $_POST["name"]; if ($name == "") { echo "You didn't type anything"; } I've written scripts like this and tested them on a GOdaddy server, and they always worked fine. Now, after testing scripts like that on my own server (WAMP2 [PHP5, Mysql, Apache]), I get an error saying "Unidentified index: name", and so I have to nest that if statement AS WELL AS the variable assignment inside another if statement like this: if (isset ($_POST["name"])) { $name = $_POST["name"]; if ($name == "") { echo "you didn't type anything. } } The error doesn't actually stop the script from running, but a medium sized box appears in the browser with the error message contained that's after the element in the document of which is getting an invalid error. Which way is truly the correct way? Because now that I have to use the second way in order for my scripts to run correctly on my own server, I have to write more code and it all gets disorganized and more complicated to read. So...is this a configuration thing that I can tweak in WAMP2 to stop messages like that from popping up? Or is the second way the way you're supposed to do it? Also, I was wondering why ereg got deprecated and what the replacement of it is in PHP5? I've asked before and even googled it but I simply get taken to a "Pearl" function on PHP.net. I'm not sure what it is, or how to use it, and haven't got any hints from either PHP.net or anywhere else. Any suggestions? I'm trying to either update my database if some data matches the if statement, or insert the data in a new row if it doesn't match (if possible). The code will update the database just fine if the data matches, but if not, it won't insert the new data. (When I leave off the if statement it will insert just fine). I fear I'm not using the if...else correctly. Thanks for any help. <?php header("Location: admin_schedule.php"); include("opendatabase.php"); $date=("$_POST[gamedate]"); $week=("$_POST[Week]"); $game=("$_POST[Game]"); $hometeam=("$_POST[team_name_1]"); $awayteam=("$_POST[team_name_2]"); $check = mysql_query("SELECT week_id,game_id FROM schedule"); $row[] = mysql_fetch_array($check); if ($row[week_id]='$week' && $row[game_id]='$game') { mysql_query("UPDATE schedule SET week_id = '$week', game_id = '$game', date = '$date', H_team = '$hometeam', A_team = '$awayteam' WHERE week_id = '$week' AND game_id = '$game'"); } else { mysql_query("INSERT INTO schedule (week_id,game_id,date,H_team,A_team) VALUES('$week','$game','$date','$hometeam','$awayteam')"); } mysql_close($con); the image in my comments box wont show up it gives me an error Code: [Select] Notice: Undefined index: avatar in /home/ecabrera/public_html/profile.php on line 277 and i dont whats wrong with it Code: [Select] // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br($row['comment']); $date = $row['date']; $avatar = $row['avatar']; echo "<img src='avatars/$avatar'></img><a href='$site/profile?id=$getid'></a> <b> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area Hi I have plans in developing a connect function for remote login to my web side. I can't find any useful on Google. Some idees on how to code a API connect button? Something similiar to Facebook connect, Twitter connect etc. BUT this should not rely on facebook api. I'm going to make my own stand alone api. I know I need to use REST in backend, but I'm missing the knowledge to know how to send / recive the login data, and how to know when a user are online or not. I'm greatfull for any help. Also links. And also tips on how to make a developer plattform for apps, much like the way Facebook have it. Hi, I hope someone can help me. I am trying to generate a script for our Intranet that tells me which birthdays = today. My field in my table = d/m/y, eg 09/05/2011 (9 May 2011). How do I get the script to just look at the day & month, not the year? My script looks like this: Code: [Select] <?php echo date("d/m/Y") . "<br />"; $myDate = date('d/m/Y'); $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); $sql = "SELECT * FROM detail WHERE dob='$mydate'"; $result=mysql_query($sql); echo mysql_num_rows($result); ?> I want to gettwitter feeds, this gives me a xml http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3 based on this: http://www.w3schools.com/PHP/php_xml_simplexml.asp i try to get the xml with: <?php$xml = simplexml_load_file("http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3");?>() i get this error: Quote Warning: simplexml_load_file(http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/vhosting/x/vhost0033377/domains/doekewartena.nl/htdocs/www/temp/twitter03.php on line 2 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://twitter.com/statuses/user_timeline.rss?screen_name=fleuragemapvv&count=3" in /home/vhosting/x/vhost0033377/domains/doekewartena.nl/htdocs/www/temp/twitter03.php on line 2 i have no clue, i'm very new to php can i even use simplexml_load_file cause it has no .xml file type extention. Hello, Alright I am having a few issues here. Let me explain what I am doing...this is a script that allows a customer to split an order..he can split certain items out of one order and it will create another order with the items he split added to this order, and then subtracting the items from the old order. The products are stored in one field called products, they are stored in a delimited list like this qty, product name, price each, product id | qty, product name, price each, product id |etc. Now, before you say why are you storing your products like that?? The reason I have to store my products like so is because the customer does not want the products stored in the order table to be dependent off the products table like they were before. In that case if he modified a product it would modify all of the orders with that product stored in them. Make sense? I am aware a delimited list probably wasn't the best way to do this but it was the best way I could think of. Ok here is my list of issues. 1) Everytime you split an order, it is not creating a new order to store the items that were split into. It created an order the first time I did it, and now all it does is it keeps updating the products field in that order, rather than creating a new order. 2) Next I do not know how I can update the old products (stored in the $prod array). It needs to update the products qtys after the order was split, and then if all of the qty for that product were moved to the new order it just needs to remove that product from the $prod array rather than updating the quantity. The code is below. Please let me know if I can provide any more information to help! Thanks everyone! // Get Old Order $get_order = @mysql_query("SELECT * FROM orders WHERE order_id = {$_POST['order_id']}"); $order = @mysql_fetch_assoc($get_order); // Get Old Order Items $products = $order['products']; //breaking products text down for display $prod = array(); $_products = explode('|', $products); foreach ($_products AS $p) $prod[] = explode(',', $p); /* $get_items = @mysql_query("SELECT product_id, qty FROM order_items WHERE order_id = {$order['order_id']}"); $items = array(); while(($row = @mysql_fetch_assoc($get_items)) !== false) { $items[] = $row; } */ if(empty($prod)) { header("Location: tracking.php"); die(); } // Create New Order mysql_query("INSERT INTO orders SET customer_id = {$order['customer_id']}, order_status = {$order['order_status']}, order_date = '{$order['order_date']}', order_date_paid = '{$order['order_date_paid']}', order_shipping = '{$order['order_shipping']}', order_shipping_fee = '{$order['order_shipping_fee']}', order_insurance = '{$order['order_insurance']}', order_insurance_fee = '{$order['order_insurance_fee']}', order_insurance_total = '{$order['order_insurance_total']}', order_grand_total = '{$order['order_grand_total']}', order_date = '{$order['order_date']}', order_filled = '{$order['order_filled']}', order_ship_date = '{$order['ship_date']}'"); $get_new_order = @mysql_query("SELECT MAX(order_id) AS order_id FROM orders") or die(mysql_error()); $new_order_id = @mysql_result($get_new_order, 'order_id', 0); // Add Items to New Order & Remove Items from Old Order $new_items = array(); $_new_items = ''; foreach($prod as $p2) { for($i = 0; $i < $p2[0]; $i++) { if(!empty($_POST[trim($p2[3]).'_'.$i])) { $new_items[trim($p2[3])]++; } } } //construct new static products list foreach($new_items as $id=>$qty) { $get_product = mysql_query("SELECT name, price FROM products WHERE product_id = '{$id}'"); $got_product = mysql_fetch_assoc($get_product); $_new_items .= $qty.','.$got_product['name'].','.$got_product['price'].','.$id.'|'; //echo $id.' - '.$qty.'<br>'; } //remove last character in products text before going into DB $_new_items = substr_replace($_new_items ,"",-1); //update products field in new order mysql_query("UPDATE orders SET products = '{$_new_items}' WHERE order_id = '{$new_order_id}'"); Hi... I have a string (called $textData) with the following format: Code: [Select] 1. e4 {[%emt 0:00:10]} c5 {[%emt 0:00:04]} 2. c3 {[%emt 0:02:15]}etc I need to replace the square brackets/special chars within that string with " "... so my first thought was to use preg_match to find the matches.. then preg_replace/str_replace to update them. To find the patterns, I think this is correct: preg_match('/\{([^\}]*)\}/', $textData, $matches); echo print_r($matches, true); // returns Array ( [0] => {[%emt 0:00:10]} [1] => [%emt 0:00:10] ) // returns nothing else I expected the preg_match to search through the whole of $textData. Then I could replace the square brackets/special chars with a spaces. Thank you for your time!! I seem to be having a problem with directorys I cam mkdir("$userid,0755") but when i come to remove it with rmdir it doesn't remove it the directory is empty even through ftp and my control panel it won't let me delete it or change the file permissions from 755 any ideas? Hello there, well basically what this function does is look at all the entry's to find a unused port in the database but when I run the function the first time if the table is empty mysql_insert_id works fine, but then if I run it again the mysql_insert_id keeps returning 0, I am using it immediately after the query but its not working properly, can anybody shed some ideas into the matter, anything is appreciated!, thanks for your time!: function addServerToBuildPool($ServerGame, $ServerOwner, $ServerSlots, $ServerBox) { $Server = mysql_fetch_array(mysql_query("SELECT * FROM xhost_boxs WHERE box_id = '".mysql_real_escape_string($ServerBox)."'")); $AddServer = mysql_query("INSERT INTO xhost_servers (server_game, server_slots, server_owner, server_ip, server_is_setup) VALUES('".mysql_real_escape_string($ServerGame)."', '".mysql_real_escape_string($ServerSlots)."', '".mysql_real_escape_string($ServerOwner)."', '".mysql_real_escape_string($Server['box_ip'])."', 'No')"); $ServerID = mysql_insert_id(); $FindPort = mysql_query("SELECT server_port FROM xhost_servers ORDER BY server_id ASC"); $Port = 0; while($row = mysql_fetch_assoc($FindPort)) { $Port = ($Port == 0)? $row['server_port'] : $Port; if($row['server_port'] != $Port) { break; } $Port++; } mysql_query("UPDATE xhost_servers SET server_port = '".$Port."' AND server_username = 'server".$ServerID."' AND server_password = '".rand(5000000, 900000000)."' WHERE server_id = '".$ServerID."'") or die(mysql_error()); } |