Jump to content

soma56

Members
  • Posts

    185
  • Joined

  • Last visited

    Never

Everything posted by soma56

  1. How do you divide $299 lb / 6.59/kg by 100?
  2. I'm trying to figure out how to place a decimal in the first price of the following: From: $299 lb / 6.59/kg To: $2.99 lb / 6.59/kg While I was able to figure this out where the string was simply a numeric value.. // get last two digits of number $l2d = substr($price, -2, 2); // place decimal before the last two digits of the number $price = substr_replace($price, '.', -2, 2) . $l2d; I'm baffled at where to start with this..
  3. From what I understand we can use ucfirst to convert the first letter within a string to upper case. What I would like to know is if there is a function that exists that would convert the first letter of every paragraph to upper case. For example: From: This is a paragraph. is this the car blue? let's go for a pint of beer! To: This is a paragraph. Is this the car blue? Let's go for a pint of beer! Does any such function exist?
  4. I found a pretty cool function that allows me to ping Pingomatic for new blogs that I have. Great. Now I can automate the process instead of manually going to their website. My problem is actually simple. Sometime Pingomatic is quite busy and is unable to receive the request. I want to be able to check the status of my ping request but I don't know how to get this specific field/variable? from the result. Here is the ping script: $title = "My blog title"; $url = "http://mynewbloglink"; function pingomatic($title,$url,$debug=true) { $content='<?xml version="1.0"?>'. '<methodCall>'. ' <methodName>weblogUpdates.ping</methodName>'. ' <params>'. ' <param>'. ' <value>'.$title.'</value>'. ' </param>'. ' <param>'. ' <value>'.$url.'</value>'. ' </param>'. ' </params>'. '</methodCall>'; $headers="POST / HTTP/1.0\r\n". "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)\r\n". "Host: rpc.pingomatic.com\r\n". "Content-Type: text/xml\r\n". "Content-length: ".strlen($content); if ($debug) nl2br($headers); $request=$headers."\r\n\r\n".$content; $response = ""; $fs=fsockopen('rpc.pingomatic.com',80, $errno, $errstr); if ($fs) { fwrite ($fs, $request); while (!feof($fs)) $response .= fgets($fs); if ($debug) echo "<xmp>".$response."</xmp>"; fclose ($fs); preg_match_all("/<(name|value|boolean|string)>(.*)<\/(name|value|boolean|string)>/U",$response,$ar, PREG_PATTERN_ORDER); for($i=0;$i<count($ar[2]);$i++) $ar[2][$i]= strip_tags($ar[2][$i]); return array('status'=> ( $ar[2][1]==1 ? 'ko' : 'ok' ), 'msg'=>$ar[2][3] ); } else { if ($debug) echo "<xmp>".$errstr." (".$errno.")</xmp>"; return array('status'=>'ko', 'msg'=>$errstr." (".$errno.")"); } } pingomatic($title,$url,$debug=true); This script works and when Pingomatic 'is available' returns something to the effect of Thanks for pinging, you're blog is being forwarded...etc. etc. When Pingomatic is too busy I receive the following result: HTTP/1.1 200 OK Server: nginx Date: Mon, 30 Apr 2012 22:23:17 GMT Content-Type: text/xml;charset=utf-8 Connection: close Content-Length: 390 <?xml version="1.0"?> <methodResponse> <params> <param> <value> <struct> <member><name>flerror</name><value><boolean>1</boolean></value></member> <member><name>message</name><value><string>Pingomatic is a bit overloaded at the moment</string></value></member> </struct> </value> </param> </params> </methodResponse> What I'm trying to get in a variable is the '<member><name>message' result. In this case it's "Pingomatic is a bit overloaded at the moment". This way I can try to ping the server again later at another time knowing that the ping was not successful. What I've tried: I've attempted to see if the 'message' (Pingomatic is a bit overloaded at the moment) is in some of the variables within the original function: $pingresponse = "<xmp>".$errstr." (".$errno.")</xmp>"; $pingresponse2 = "<xmp>".$response."</xmp>"; $pingresponse3 = array('status'=> ( $ar[2][1]==1 ? 'ko' : 'ok' ), 'msg'=>$ar[2][3] ); echo "Ping Server Response : Debug: ".$debug." Errstr :".$errstr." Errno: ".$errno."Response: ".$response; But it isn't. My plan was to use strpos to search for the term "Pingomatic is a bit overloaded at the moment" in which I'll be able to know whether or not the ping was successful or not. Any ideas?
  5. Hi, I'm new to mysql and wanted to know if something like this was possible: $query = "SELECT * FROM tableX WHERE status != 'Error' AND id != (SELECT id FROM tableY) LIMIT 1"; $get_incomplete_keyword = mysql_query($query); The idea is to only select from table 'x' where the id is NOT in table 'Y'. Is this possible?
  6. I wasn't too sure if this should be in the MySQL help section so please (admin/mods) feel free to move this if you feel it's necessary. I'm attempting to connect to a URL through cURL that is being grabbed from a mysql table. The url within the table is: http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html" When I plug this into firefox it works. When using it through cURL directly (see below) it works. $url = "http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html"; // create a new curl resource $ch = curl_init(); // set URL to download curl_setopt($ch, CURLOPT_URL, $url); // user agent: curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // remove header? 0 = yes, 1 = no curl_setopt($ch, CURLOPT_HEADER, 0); // should curl return or print the data? true = return, false = print curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 60); // download the given URL, and return output $page = curl_exec($ch); However, when I grab the url from a table within mysql it does not work and no curl error (or any error for that matter) is returned. $get_url_links = "SELECT * FROM tabe"; $url_link = mysql_query($get_url_links); $row = mysql_fetch_array($url_link); $url = $row['link']."<br />"; I'm suspecting this is some kind of encoding issue. I've tried $url = mysql_real_escape_string($url); --- before entering it into the table $url = mysql_real_escape_string($url); --- before calling cURL mysql_query("set names 'utf8'"); --- before inserting the url into the table I've also set the column table type to 'text'. Suggestions appreciated.
  7. Thank you. I like my way better though (just kidding).
  8. Ha. Got it, but something tells me there's probably over a hundred better ways to get this value: foreach ($arr as $var){ foreach ($var as $vv){ foreach ($vv as $v){ foreach ($v as $i){ echo $i; } } } }
  9. Thanks, getting somewhere: array(1) { ["data"]=> array(1) { ["translations"]=> array(1) { [0]=> array(1) { ["translatedText"]=> string(11) "Hello World" } } } } I appreciate it and I'll see if I can learn how to figure out the rest.
  10. Thanks, this is where I'm at right now: $translate = file_get_contents("https://www.googleapis.com/language/translate/v2?key=MyKey&q=$content&source=es&target=en"); $obj = json_decode($translate); print "TEST 1".$obj->{'translatedText'}; echo "<br />"; $response = json_decode($translate); echo "TEST 2".$response->data->translations->translatedText; echo "<br />"; echo "TEST 3".$response->translatedText; echo "<br />"; $response2 = json_decode($translate, true); echo "TEST 4".$response2['translatedText']; echo "<br />"; No results returned but 'json' is working based on an example from php.net. Got a feeling I'm in the right direction?
  11. I've signed up for Google's translating service and I'm able to get results, however, it's wrapped around some information. Here's an example: //Content to translate - Spanish for 'Hello World' $content = urlencode("Hola Mundo"); $translate = file_get_contents("https://www.googleapis.com/language/translate/v2?key=MyKey&q=$content&source=es&target=en"); echo $translate; The code returns { "data": { "translations": [ { "translatedText": "Hello World" } ] } } All I want is the result Hello World I tried using str_replace but it does not work through file_get_contents. The Google Translate does not provide any information on how to do this. Does anyone have any ideas?
  12. Here's the page which displays the tables available for download split into 10k pieces <? //Connect to Database require("db_connect.php"); $current_table = $_GET['current_table']; //determine table total $what_is_the_total = "SELECT * FROM $current_table"; $result_total = mysql_query($what_is_the_total); $num_rows = mysql_num_rows($result_total); //determine keywords completed $result_completed = mysql_query("SELECT * FROM $current_table WHERE status = 'Complete'"); $num_rows_completed = mysql_num_rows($result_completed); //Determine percentage complete $percentage = round($num_rows_completed * 100 / $num_rows)."%"; $rangeend = 10000; $row_counter = 1; $add = 0; $get_first_date = "SELECT * FROM $current_table WHERE status = 'Complete' AND date = '2012-03-17' ORDER BY mysql_id ASC LIMIT 1"; $first_date = mysql_query($get_first_date); $first = mysql_fetch_array($first_date); $rangestart = $first['id']; ?> <div style="text-align:center;"> <table id="tbl_data"> <thead> <tr> <th scope="col">ID</th> <th scope="col">MySQL ID Range</th> <th scope="col">CSV ID Range</th> <th scope="col">Keyword Range (Export)</th> <th scope="col">Date Range</th> <th scope="col">Time Range</th> </tr> </thead> <tbody> <?PHP $get_all_completed = "SELECT * FROM $current_table WHERE status = 'Complete' AND id >= $rangestart"; $completed = mysql_query($get_all_completed); while ($row = mysql_fetch_array($completed)){ $id = $row['id']; $rangest = $row['mysql_id']; $rangest = $rangest + $add; $rangeend = $rangest + 10000; $get_start_ranges = "SELECT * FROM $current_table WHERE status = 'Complete' AND mysql_id = $rangest"; $start_ranges = mysql_query($get_start_ranges); $start_range = mysql_fetch_array($start_ranges); $start_id = $start_range['id']; $start_keyword = $start_range['keyword']; $start_date = $start_range['date']; $start_time = $start_range['time']; $get_end_ranges = "SELECT * FROM $current_table WHERE status = 'Complete' AND mysql_id = $rangeend"; $end_ranges = mysql_query($get_end_ranges); $end_range = mysql_fetch_array($end_ranges); $end_id = $end_range['id']; $end_keyword = $end_range['keyword']; $end_date = $end_range['date']; $end_time = $end_range['time']; if ($end_range == ""){ $get_last_keyword = "SELECT * FROM $current_table WHERE status = 'Complete' AND id >= $rangest ORDER BY mysql_id DESC LIMIT 1"; $last_keyword = mysql_query($get_last_keyword); $final_keyword = mysql_fetch_array($last_keyword); $end_id = $final_keyword['id']; $end_keyword = $final_keyword['keyword']; $end_date = $final_keyword['date']; $end_time = $final_keyword['time']; $end = 1; } echo " <tr> <td>$row_counter</td> <td>$rangest - $rangeend</td> <td>$start_id - $end_id</td> <td><a href=\"export.php?current_table=$current_table&start_id=$start_id&end_id=$end_id\">$start_keyword - $end_keyword</a></td> <td>$start_date - $end_date</td> <td>$start_time - $end_time</td></tr>"; if ($end == 1){ break; } $add = $add + 10000; $row_counter++; } ?> </tbody></table> Here is the script that process the range into CSV for the client: <?PHP ini_set('memory_limit', '512M'); //Connect to Database require("db_connect.php"); $current_table = $_GET['current_table']; $start_id = $_GET['start_id']; $end_id = $_GET['end_id']; $current_table_results = $current_table."_results"; $query = "SELECT * FROM $current_table_results where id between $start_id and $end_id"; $result = mysql_query($query) or die("Error executing query: ".mysql_error()); $row = mysql_fetch_assoc($result); $line = ""; $comma = ","; foreach($row as $name => $value) { $line .= $comma . '"' . str_replace('"', '""', $name) . '"'; $comma = ","; } $line .= "\n"; $out = $line; mysql_data_seek($result, 0); while($row = mysql_fetch_assoc($result)) { $line = ""; $comma = ","; foreach($row as $value) { $line .= $comma . '"' . str_replace('"', '""', $value) . '"'; $comma = ","; } $line .= "\n"; $out.=$line; } header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=$current_table-$start_id-$end_id.csv"); echo $out; exit; ?> I'm assuming there is a much more efficient way to: A - download all the results from a specific table into CSV without having to split it up in a way that doesn't flag the memory. and/or B - Place the tables into a zip file so that the client can simple 'download' everything without having to waste time downloading each individual file.
  13. I have dozens of tables that a client needs to download through the web. I can use PHP to convert the tables within the database to a CSV however I have to split the files into 10k result chunks otherwise the server gets overloaded with memory. I already raised the memory limit within the script that is downloaded (ini_set('memory_limit', '512M') which is able to make this happen. Downloading these files piece by piece is a really time consuming. Is there a memory safe and efficient way to combine all my tables as CSV's and into one zip them into one master download? PHPMyAdmin seems to do this smoothly, however, I need an online interface for the client to export the data directly...
  14. Perhaps, however, it runs flawlessly on the same hosting companies VPS and I don't know the first thing about cli. Is this what you mean?... Server Limit 1000 Max Clients 500 Max Requests Per Child - 0 (unlimited) Keep-Alive - On Keep-Alive Timeout - 50 Max Keep-Alive Requests - Unlimited Timeout - 1000 I'm spent and I'm tired of my heart palpitating and cramping because of this. It's been a week and I think I've changed just about every php.ini, hta and apache setting there is. I'm going to ask the hosting company to upgrade to the latest version of PHP to see if that solves the issue but something tells me I'm just wasting my time.
  15. max_execution_time = 0 max_input_time = 0 memory_limit = 512M output_buffering = 1024 implicit_flush = On Nothing. Still freezing. I thought upgrading to an additional 6 gigs of ram on a dedicated would be a good thing. The mystery is that there is no errors reported back. VPS > Script executes and runs flawlessly Dedicated > Freezes for no reason at all after about an hour My next steps: I'm reviewing the differences between the htaccess file, php.ini file and Apache settings within WHM to see if I can match the VPS to the dedicated. Hostings next steps: They're reverting the PHP version from 5.2.9 to 5.2.17 on the dedicated server to match the same version on the VPS. This is a total mind f#$... Suggestions and sympathies welcome...
  16. Change: echo "the ref number is $last"; to echo "the ref number is ".$last; This isn't what's causing the error though. And as far as the mysql statement: $query = mysql_query("SELECT * FROM news WHERE `ref` = '$last'"); I'd take out the ` and either remove them completely or change them to ' $query = mysql_query("SELECT * FROM news WHERE ref = '$last'"); Make sure the table name (news) and the column within the table (ref) match perfectly in the DB.
  17. This is mind bender. I recently upgraded from a VPS to a Dedicated server. The script is a data mining tool that primarily uses cURL. It worked flawlessy on the the VPS. Because it was the same hosting company everything was migrated and done so smoothly to the new dedicated. Now, the program hangs for no reason at all. The times vary but I'll usually get about an hour of the script before it hangs. It used to run for hours at a time on the VPS. While I do see some 'notices' and cURL timeouts - there are no error messages echoed out when the program hangs and there is nothing within the error log on the server to indicate anything in terms of why. The program simply 'freezes'. I think I've spent the last three days modifying the php.ini file. Here are some settings which may be of interest? post_max_size = 16M log_errors = On max_execution_time = 0; (From what I understand is unlimited). max_input_time = 0 ; memory_limit = 128M; At the top of every page within my script: set_time_limit(0); error_reporting(E_ALL); The dedicated is an 8 gig Linux box running Apache. Speaking of which, here are some settings within WHM for Apache: Max Clients 500 Max Requests Per Child - 0 (unlimited) Keep-Alive - On Keep-Alive Timeout - 50 Max Keep-Alive Requests - Unlimited Timeout - 1000 Because the script works on another VPS that I have within the same hosting company can someone direct me with what I should be looking for and/or comparing between both servers? What are the most common reasons for a PHP script to freeze from a server setting standpoint?
  18. Ok, I'm assuming then that hexdec would change to octdec. No luck: $decodethis = "&#117"; $re = '/&#x([0-9A-F]{2});/ie'; $decodethis = preg_replace($re, 'chr(octdec("$1"));', $decodethis); echo $decodethis; html_entity_decode also does not work: $decodethis = "&#117"; $decodethis = html_entity_decode($decodethis); echo $decodethis; The browser display is fine, however, the source code is still showing the octal encoded value...
  19. I can seem to 'convert it' where displaying it is concerned but I don't know enough about preg_match to convert it within the source: $decode = "P&#000117bli&#000115kie m&#000111bil&#000111 &#000116elef&#000111&#000110&#000117 &#000116&#000299kli "; $decode = htmlentities($decode ); echo $decode; echo "<br />"; $decode = html_entity_decode($decode ); echo $decode; echo "<br />"; echo htmlspecialchars_decode($decode); It's still showing up as P&#000117bli&#000115kie m&#000111bil&#000111 &#000116elef&#000111&#000110&#000117 &#000116&#000299kli ...in the source. Googling a solution for this issue is next to impossible when you don't know anything html decoding. The solutions (that I have found and tried anyways) seem to be focused on providing the correct on-page display rather then the source code. The puzzling part for me is that I've always thought of preg_match as find/replace sort of function. If that's the case how would anyone know that &#000117 is equal to the letter u? My face is twitching at this point
  20. Great, that seems to have solved half my issue. It seems some of the characters are still funny. I think this has something to do with the website being Latvia (and hence some of the characters): Here's the text exactly as it is displayed in firefox: Publiskie Here is what the source code looks like for the above (Latvian) word: P&#000117bli&#000115kie So it seems that (for whatever reason) it's translating two of the letters (U and S) to the following: &#000117 &#000115 These seem to be a little longer then the ones in my previous post. If they are not HTML entity sequences then what are they?
  21. Thanks for everyones input. The mysql Collation is latin1_swedish_ci (the default for varchar). Although it displays in Firefox correctly I can see in the source that the text is as follows: &#x53;&#x49;&#x41; The above reads 'SIA'. The gibberish is how it updates into my database. I tried to detect the encoding which stated it was ASCII. I attempted to change it to UTF-8 but it still says that it's ASCII: echo mb_detect_encoding($result); echo "<br />"; $current_encoding = mb_detect_encoding($result, 'auto'); $result = iconv($current_encoding, 'UTF-8//IGNORE', $result); echo mb_detect_encoding($result); echo "<br />"; I don't know anything about encoding and I'm really confused. How do I convert something like &#x53;&#x49;&#x41; to simple plain text that I'm able to upload to my DB?
  22. Wow, what a pain. I have some strings that contains some f-uped Lativa characters. I'm having a heck of a time trying to convert them over to anything. Mysql won't recognize them when I attempt to update a table and hence they must be changed. This character, for example, looks like a simple small i: ī ...but it's not. Here is a page where you'll see all of them with (http://www.eki.ee/letter/chardata.cgi?lang=lv+Latvian&script=latin). And for the record here is all of them. ē Ē, ŗ Ŗ, ū Ū, ī Ī, ā Ā, š Š, ģ Ģ, ķ Ķ, ļ Ļ, ž Ž, č Č, ņ Ņ This is what I have tried in terms of converting them to be used with mysql: Didn't work: $result = preg_replace('/ī/','i', $result); Didn't work: $current_encoding = mb_detect_encoding($result, 'auto'); $result = iconv($current_encoding, 'UTF-8', $result); Didn't work: $result = str_replace("ī", "i", $result); I'm baffled at why I can't get these characters to convert in PHP. It seems pretty direct to me. Can anyone recommend anything?
  23. I'm working on an application that uses cURL but for the life of me I can't figure out why the proxy isn't working through cURL. The proxy works fine through Firefox. Here's a very simple example of cURL and with respect to how I'm trying to connect: <?PHP $url = 'http://www.mysite.com'; //URL to get $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); // no headers in the output curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // output to variable curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0); curl_setopt($ch, CURLOPT_PROXY, 'IP:PORT'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25); $data = curl_exec($ch); curl_close($ch); return $data; echo $data; ?> Can anyone suggest why this wouldn't work with a working proxy? I'm dying here....
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.