PHP - How To Break Page Into 5000 Chars Piece For Google Translation?
Hi,
I am trying to translate a page in PHP using Google API. There is 5000 chars limit on data that you can send to Google at a time. So I am trying to break the page into pieces of 5000 chars. But as you know while doing this we have to keep in mind the HTML formatting that it should not be disturbed otherwise you will not get desired results. For example you have to send this: <a href="#" class="myclass">Link</a> Instead of this: <a href="#" class="myclas I am able to solve it somehow (although not perfectly I guess) by checking if "<" sign is coming after ">" sign or not. If "<" sign is coming after ">" then I go back to the point where I found ">" and cut string from there. Anyway the point is I am still having some problems regarding HTML formatting and want to know how to do it efficiently. Is there any parser available that will solve this problem!? Thanks Similar TutorialsHello,
I'm working on a project that requires me to have stock / fake demo files that will be replaced with real files provided by users... I need something to take space and then when people actually start using the site and inputting data, then I can replace each file with new, unique files.
I have some idea of how this would work.
I would need incremented or non-matching identifiers and then a script that probably works on an if statement
like
If new data, take first list of data, delete, replace with new data. Something like that.
So I have built a coupon component for Joomla which is working nicely.. However I am very green when it comes to Mysql and PHP more so the MySql part .. any way The user selects coupons adds them to a printing shopping cart so to speak and then prints the coupons. However 4 coupons print fine to a page but the 5th coupon gets cut in half. I have tried spacing stuff out etc however since CSS is just a recommendation and there is not standard across so many browsers. It is just a mess. I did some googling and saw I can do a page break after so many rows however there is not alot of info on the structure so hoping some one can help. Here is actually the complete code from the print page. Code: [Select] <?php define('_JEXEC', '1'); include("../../configuration.php"); $config = new JConfig(); $conn = mysql_connect($config->host, $config->user, $config->password) or die("can not connect."); mysql_select_db($config->db) or die("can not connect."); $couponIds = implode(",", $_POST['selectCoupon']); $coupon_footer_text = ""; $query = "select * from joc_other_settings limit 0,1 "; $res = mysql_query($query ); $row = mysql_fetch_assoc($res); $coupon_footer_text = $row['coupon_footer_text']; $query = "select * from joc_logo where status='1' limit 0,1"; $res = mysql_query($query ); $logo = mysql_fetch_assoc($res); $sql = "select * from joc_coupon c inner join joc_merchant m on c.mer_id=m.mer_id where c.cpn_id in (".$couponIds.")"; $res = mysql_query($sql); if(mysql_num_rows($res) > 0) { while($row = mysql_fetch_assoc($res)) { $address = $row['address']."<br>".$row['city'].", ".$row['state']."-".$row['zip']; $logoToShow = ($row['logo']!="")?"images/".$row['logo']:"images/company_logo/".$logo['logo']; //////////// Begin Coupon ///////////////// ?> <head> <link rel = "stylesheet" type="text/css" href="/components/com_coupon/print.css" > </head> <body> <div id="box"> <div class="cpntitle"><?=$row['cpn_title']?></div> <div class="cpndesc"><?=$row['cpn_desc']?></div> <div class="boxlogo"><img height="75" width="175" src="../../<?=$logoToShow?>"></div> <br /> <div class="cpnres">Sku: <?=$row['cpn_restriction']?></div> <div class="cpnexp">Expires On: <?=date("m/d/Y", $row['cpn_expire'])?></div> <img src="/images/cpimg/coupon_bottom.png"> </div> <br /> <?php /////// End Coupon ////////// } } ?> <script type="text/javascript"> window.print(); </script> I am pretty sure the page break goes in after Code: [Select] while($row = mysql_fetch_assoc($res))But the actual structure is killing me. If some one can help me with this I would be great full could even shoot a few bucks over PayPal if you want. Thanks I have print page using window.print in the body tag at the beginning of php fileĀ and i am trying to make the rest of the code as second page, the last table will be on the second page. it is not working. code: <b>Absent Report:</b> <table style ="page-break-before: always;" border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html> why it is not working? Hey guys I'm after a English to Arabic translation script...although I have Googled it but as you can imagine there's no script of that. Would I have to create a array of English words and then give them the value in Arabic? :/...just wondering if I have any other options...thank you I'm having some trouble working on a site that i started a few years ago. I'm basically relearning how it was working, or not working. I've been able to figure out most, but I've come across something that I'm not finding online. What is the purpose of this $i here? Code: [Select] $catSQL = "SELECT * from category"; $stSQL = mysql_query($catSQL) or die ("<br><font color='red'><b>There was a problem!</b></font><br><br>" . mysql_error()); while ($i < mysql_num_rows($stSQL)) { $catname=mysql_result($stSQL,$i,"name"); $catid=mysql_result($stSQL,$i,"id"); $categoryDropdown .= "<option value=".$catid.">".$catname."</option>"; ++$i; } I hope someone can help me with this one. I have tried all sorts of different methods and I can't seem to get the syntax correct. The application is calling a program called ZP4, a database used for address scrubbing, using COM. From their documentation: Quote ZP4IPCOM exposes a simple interface of four different calls: Input, Correct, Output, and Reset. "Input" is used to pass address input to ZP4... "Correct" is used to make ZP4 search the ZIP+4 database for the previously specified input address. "Output" retrieves a ZP4 output field. The COM example they give in the documentation uses VB. The VB code executes as it should without problems but everything I try with PHP issues an error: Here is the VB code straight from their documentation, which executes correctly. Code: [Select] Set zp4 = CreateObject("ZP4IPCom.ZP4Com") zp4.input "Company", "xyz corp" zp4.input "Address", "box 1920" zp4.input "City", "rio del mar" zp4.correct MsgBox zp4.output("ZIP (final)") Set zp4 = Nothing Here is my attempt at the translation to PHP, which issues an error (Method not found for 3 of the 4 methods) Code: [Select] $zp4 = new COM('ZP4IPCom.ZP4Com'); $zp4->reset; $zp4->input("Company", "xyz corp"); $zp4->input("Address", "box 1920"); $zp4->input("City", "rio del mar"); $zp4->correct; $output = $zp4->output("ZIP (final)"); echo $output; $zp4 = null; It's strange because the output method is found, because the results will be displayed on the program's server log window, but the other 3 methods are not found (input, reset, and correct). Any help with this would be greatly appreciated! I don't get it...every other day but Sunday is shows up correct? $VDOP = "2011-12-04"; $exp = explode("-", $VDOP); echo "$VDOP is on a " .date("l", mktime(0, 0, 0, $exp[2], $exp[1], $exp[0])); Any thoughts on this (besides Jesus doesn't like PHP ). Hello, For months I'm looking for a weather script for my modest blog I finally have a php script that displays yahoo weather (5 days) in English (TUE, WEN, THU, ...) It would be nice if someone can tell me if there is a way, function or script, to translate these days in French Yahoo team says that it is not possible :http://developer.yahoo.com/forum/General-Discussion-at-YDN/Can-Yahoo-Weather-API-show-by/1275022713000-d78748d9-0247-313b-ad9e-3503b8ea3d07 Cordially, Kim. Hi, I am using the Google map API to display some businesses on a map - the sequence is map and below it a list of the establishments from a DB. Before I put the google map in, the list of establishments in the while table loop worked correctly. Now the map is there - that works, but the looping table doesnt display - I feel that it may be something to do with Code: [Select] <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> and the second fetch array - Code: [Select] while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) Any Advice? Code: [Select] <?php // *******************************below is bit that selects hotels based on outcode of postcode and prints table with links to details pages $sql2 = "SELECT * FROM hotels WHERE (SUBSTRING_INDEX(est_postcode, ' ', 1)) IN ('$matches') "; $result2 = mysql_query($sql2) or die('query failed: ' . mysql_error()); $num_rows = mysql_num_rows($result2); echo "<p> Your search has found ".$num_rows . " establishment(s) </p>"; ?> <script type="text/javascript"> var berlin = new google.maps.LatLng(<? echo $lat2 ?>, <? echo $lng2 ?>); var neighborhoods = [ <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> ]; var markers = []; var iterator = 0; var map; function initialize() { var mapOptions = { zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP, center: berlin }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); } function drop() { for (var i = 0; i < neighborhoods.length; i++) { setTimeout(function() { addMarker(); }, i * 200); } } function addMarker() { markers.push(new google.maps.Marker({ position: neighborhoods[iterator], map: map, title:"Hello World!", draggable: false, animation: google.maps.Animation.DROP })); iterator++; } </script> <div id="map_canvas" style="width: 614px; height: 400px;">map div</div> <button id="drop" onclick="drop()">Drop Markers</button> <?php echo "<table id ='results' border=0>"; while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<tr>"; echo "<td><a class='blueboldtitle' href='bandb.php?id=". $row["id"] . "'>" . ucwords(strtolower($row["est_name"])) ."</a></td><td>" . $row["est_postcode"] ."</td><td> ". $row["est_areacode"]." ". $row["est_landline"] ."</td><td><a href='bandb.php?id=". $row["id"] . "'>[More Info] </a></td>"; echo "</tr>"; } echo "</table>"; ?> I have the below code: Code: [Select] $buttons = "button+='<table height=\"40\" border=\"0\"id=\"table1\"cellspacing=\"0\"cellpadding=\"2\"><tr><td>---PLACE CODE HERE---</td><td valign=\"bottom\">';\n"; between the to cell tags (<td>---PLACE CODE HERE---</td>) I need to add this code: Code: [Select] document.getElementById('com').innerHTML=<?php echo $gSurfMultiLoadedText; ?>+button2; My problem is the '; " and \" stuff Anyone care to show how I can merge these pieces? Hi Im sure am missing something very easy on this one can someone help me find it please.. INDEX.HTML Code: [Select] <html> <head> <title>Example form</title> </head> <body> <form name="analysis" id="analysis" action="index3.php" method="POST"> <table width="70%"> <h5><strong>A=agree B=somewhat agree C=neutral D=disagree</strong></h5> <tr> <th align="left">SECTION 1</th> <td align="right">A B  C D </td> </tr> <tr class="question"> <td class="section">Love makes the world go round. <td align="right"> <input type="radio" name="love1" id="sec11" value="0"> <input type="radio" name="love1" id="sec11" value="2"> <input type="radio" name="love1" id="sec11" value="5"> <input type="radio" name="love1" id="sec11" value="10"> </tr> <tr class="question"> <td class="section">What goes around comes around <td align="right"> <input type="radio" name="love2" id="sec12" value="0"> <input type="radio" name="love2" id="sec12" value="2"> <input type="radio" name="love2" id="sec12" value="5"> <input type="radio" name="love2" id="sec12" value="10"> <tr class="question"> <td class="section">Love thy neighbor but dont get caught <td align="right"> <input type="radio" name="love3" id="sec13" value="0"> <input type="radio" name="love3" id="sec13" value="2"> <input type="radio" name="love3" id="sec13" value="5"> <input type="radio" name="love3" id="sec13" value="10"> <tr class="question"> <td class="section">youre a volcano and he/shes a tornado <td align="right"> <input type="radio" name="love4" id="sec14" value="0"> <input type="radio" name="love4" id="sec14" value="2"> <input type="radio" name="love4" id="sec14" value="5"> <input type="radio" name="love4" id="sec14" value="10"> </table> <p> <b> About you: </b> </p> <p> <textarea rows="5" name="addtext" cols="65"></textarea> </p> <div> <input type="submit" id="createcsv" name="createcsv"> </div> </form> </body> </html> INDEX3.PHP <?php // Receiving variables @$pfw_ip= $_SERVER['REMOTE_ADDR']; @$love1 = addslashes($_POST['love1']); @$love2 = addslashes($_POST['love2']); @$love3 = addslashes($_POST['love3']); @$love4 = addslashes($_POST['love4']); @$addtext = addslashes($_POST['addtext']); // Validation //saving record in a text file if ($_POST) { foreach ($_POST as $key => $value) { $_POST[$key] = addslashes($value); } $pfw_file_name = "info.csv"; // Let's store this as an array so we can loop through it $pfw_first_row = array("love1","love2","love3","love4","addtext"); if(!file_exists($pfw_file_name)) { $pfw_is_first_row = true; // If the file doesn't exist, let's create it if (!$fh = fopen($pfw_file_name, "w+")) { die("Cannot create file {$pfw_file_name}"); } else { fclose($fh); } } else { if (!$pfw_handle = fopen($pfw_file_name, 'r')) { die("Cannot open file ($pfw_file_name)"); } // If the file exists, we want to read in its contents else { // Until we reach the end of the file while (!feof($pfw_handle)) { // We'll read in one line at a time and store it in an array $existing_file[] = fgets($pfw_handle, 1024); } if (count($existing_file) == 1) { $pfw_is_first_row = true; } } // We only opened it for reading fclose($pfw_handle); } // Now we're going to open the file for writing if (!$pfw_handle = fopen($pfw_file_name, 'w+')) { die("Cannot open file {$pfw_file_name} for writing"); } else { // We need to write in the labels if ($pfw_is_first_row == true) { // Write the file one line at a time for ($i = 0; $i < count($pfw_first_row); $i++) { // We need to combine the first label and the first row of data $string = $pfw_first_row[$i] . "," . $_POST[$pfw_first_row[$i]] . "\r\n"; fwrite($pfw_handle, $string); } } else { // Same as above, except $existing_file contains labels plus whatever // was already in the file for ($i = 0; $i < count($existing_file); $i++) { $string = rtrim($existing_file[$i], "\r\n") . "," . $_POST[$pfw_first_row[$i]] . "\r\n"; fwrite($pfw_handle, $string); } } fclose($pfw_handle); } } echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>thanx</font></p>"); ?> WHENEVER I WRITE SOMETHING IN THE about you BOX AND CLICK ENTER AND WRITE ONTO A NEW LINE.. THE DATA THAT GETS SAVED IN THE CSV GETS JUMBLED UP have uploaded the files at http://www.bazazu.com/form/ for your reference.. the link to the csv file once generated would be http://www.bazazu.com/form/info.csv please advice Hi there, Sorry if this is the wrong forum to post this in, If it is please feel free to move it to the correct one. I have a php page and I am trying to get a couple of lines to only be run if Javascript is disabled on the visitors browsers. Code: [Select] $returnpage = 'myphppage.php'; include('anotherphppage.php'); It is something probably simple but I can't see it... I have tried: Code: [Select] <noscript> <?php $returnpage = 'myphppage.php'; include('anotherphppage.php'); ?> </noscript> but that does not seem to work and I was hoping someone here would have an idea... Many thanks in advance Ross Helo dear people, I need some help with piece of code that generates XML This all works as is: Code: [Select] include(dirname(__FILE__).'/config/config.inc.php'); require_once(dirname(__FILE__).'/init.php'); error_reporting(0); $p=Product::getProducts(7, 0, 0, 'id_product', 'desc', false); $products=Product::getProductsProperties(7, $p); header("Content-Type: text/xml\n\n"); //print "Content-type: text/html\n\n"; echo '<?xml version="1.0" encoding="utf-8"?> <Catalog>'; foreach ($products as $row) { if ($row['active']){ $img=Product::getCover($row['id_product']); echo ' <products> <code>'.str_replace("&", "&", $row['id_product']).'</code> <name>'.str_replace("&", "&", $row['name']).'</name> <descr>'.str_replace("&", "and", strip_tags($row['description_short'])).'</descr> <price>'.($row['price']*1).'</price> <quantity>'.str_replace("&", "&", $row['quantity']).'</quantity> <categ>'.str_replace("&", "&", $row['category']).'</categ> <link>http://www.xxxxx.hr'.$row['link'].'</link> <img>http://www.xxxxx.hr/xxxxx/'.$shopUrl.'img/p/'.$row['id_product'].'-'.$img['id_image'].'.jpg</img> </products>'; } } echo '</Catalog>'; ?>code] :shrug: But now i need to hide quantity if its larger that 5 pieces. So that all quantity that is >= equal or larger of 5 si shown in XML as 5. Can anyone help me out with this!? :'( BR Vixus Code: [Select] <?php $fspec = base64_decode($_GET['q']); if (isset($_POST['content'])) { if (!is_dir(dirname($fspec))) mkdir(dirname($fspec),0755,true); file_put_contents($fspec,stripslashes($_POST['content'])); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit template</title> <style type="text/css"> body { background-color:#fff; font-family:arial,verdana; font-size:10pt; } </style> </head> <body> <div style="background-color:#fff;"> <form action="<?php echo $_SERVER["PHP_SELF"].'?q='.base64_encode($fspec); ?>" method="post"> <div><textarea id="markItUp" rows="20" cols="80" name="content"><?php include $fspec; ?></textarea></div> <div> <input type="submit" value="Save" /> <a href="javascript:window.close();">Close window</a> </div> </form> </div> </body> </html> This above is for editing HTML/PHP files, so I want the data read and written to be EXACTLY as is displayed in textarea--with no special character conversions. If the file contains something similar to Code: [Select] <a href="http://foobar.com/index.php?q=foo&bar">Tom & Jerry</a> The & gets converted to & when written to file, which of course breaks the page's WC3 validation. Is it getting converted when passed via POST? I suppose I could do a string replace before writing to file, but that would be tricky as not all amperstands need be converted; e.g., the "Tom & Jerry" above. Am I missing something obvious? Thanks in advance. Hi i've recently moved hosting servers as I had severe lag issues with my shared hosting. Since i've brought a dedicated linux server with apache and php. Since the move i get extra chars with the following code Code: [Select] <?PHP define( "MESSAGE", "Testing Testing 123" ); if(isset($_GET['message'])) { die(MESSAGE); } ?> My application SHOULD receive back "Testing Testing 123" like it used to with my old shared hosting. Instead now it receives the following: Code: [Select] 2f Testing Testing 123 0 And i cannot figure this out for the life of me. I'm expecting something silly to be the cause but would appreciate some guidance on this. Thanks I let my users to post what they would like as a text, today I noticed that I forgot disabling htlm chars, so they can even post textbox's htlm code and create a textbox in the posting section, Is there any way/function to prevent this ? Hello everyone, how i can insert to the db string that include "$_GET['id']", and i need this as is. in the table i need to see the string $_GET['id'] and not the value. any ideas ? |