
soma56
Members-
Posts
185 -
Joined
-
Last visited
Never
Contact Methods
-
Website URL
http://socialemailextractor.net
Profile Information
-
Gender
Male
-
Location
Bahamas
soma56's Achievements

Regular Member (3/5)
0
Reputation
-
How do you divide $299 lb / 6.59/kg by 100?
-
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..
-
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?
-
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?
-
Select all from X where ID isn't found in table Y -- Is this query possible?
soma56 replied to soma56's topic in MySQL Help
Thanks, works perfect. -
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?
-
Problems using URL in cURL when grabbed from mysql table
soma56 replied to soma56's topic in PHP Coding Help
Disregard - faulty code found on my part... -
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.
-
Thank you. I like my way better though (just kidding).
-
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; } } } }
-
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.
-
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?
-
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?
-
Mass MySQL downloading - What's the most efficient way through PHP?
soma56 replied to soma56's topic in PHP Coding Help
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. -
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...