PHP - Converting Fread() To Int
Hello.
I need help adding a text file content by one and then saving. My current code is $myFile = "serving"; $fh = fopen($myFile, 'w+') or die("can't open file"); $conv = fread($fh, 4); $stringData = $conv++; fwrite($fh, $stringData); fclose($fh); I was told this would work, but of course, it doesn't. It always returns 1. I also tried casting it as an int by using $stringData = (int) $conv++; Similar TutorialsHi! I run a site the requires users to access largeish files, for download as well for streaming to the browser. It's fairly active, so assuming the worst, how bad is getting php to read the files that would be stored outside of the webroot and then getting it to echo it to a page dynamically for the browser to then read? Currently, I just have the files stored accessible to the web, but a htaccess protects them via requiring a cookie but also requires the referrer to be my site. Now I'm not totally stupid and realise those are both easily spoofed, so I'm looking for a better solution. How do the file hosting sites do it? Using a token system has to involve PHP or some other server side scripting, but then getting the server to read the file with fread() or some similar equivalent would be resource heavy, no? Is that the best way to do it? I want to load and display the content of a text file (actually it is a cache file). I tested both method using a long for loop as Code: [Select] for ($i=0; $i < 10000; $i++) { $handle = fopen("test.txt", "r"); $text = fread($handle, filesize("test.txt")); fclose($handle); echo $text; }and Code: [Select] for ($i=0; $i < 10000; $i++) { $text = file_get_contents("test.txt"); echo $text; } but the results were similar, though with a large distribution of the comparative data. The speed of a method was 0.5 to 2.0 faster than the other one (in various runs). Which method do you recommend? Could you please quote the pros and cons of each method? Hi all I am pulling my hair out trying to get the following script to work Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect("*.*.*.*", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "root", "********")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // execute a command if (!($stream = ssh2_exec($con, "ls -al" ))) { echo "fail: unable to execute command\n"; } else { echo "should be ok"; // collect returning data from command stream_set_blocking($stream, true); $data = "path to file checked by logging into WINSCP and looking at properties. Is a .txt file"; echo $data; while ($buf = fread($stream,4096)) { $data .= $buf; } fclose($stream); } } } Basically shouldnt this display the contents of the file to me? On screen I just get Quote okay: logged in... should be ok What is my error? Thanks Hi i am trying to read a page that i open but i keep getting errors and dont know why any ideas. The code im using is: foreach($url_extq_data as $a) { $var .=$a; } // now replace all the tags in the substring and out put the data $from = array("{our_track}", "{name}", "{surname}", "{email}", "{title}", "{gender}", "{dobday}", "{dobmonth}", "{dobyear}", "{address}", "{address2}", "{town}", "{county}", "{postcode}", "{tel}", "{mobile}", "{timestampu}", "{timestampr}", "{username}", "{password}", "{company}", "{siteurl}", "{fax}", "{tracking}"); $to = array("$our_id", "$name", "$surname", "$email", "$title", "$gender", "$dobday", "$dobmonth", "$dobyear", "$address", "$address2", "$town", "$county", "$postcode", "$tel", "$mobile", "$timestampu", "$timestampr", "$username", "$password", "$company", "$siteurl", "$fax", "$trackit"); $final_url = str_replace($from, $to, $var); // open url and wait for response $handle = fopen('$final_url', "r"); echo $final_url; ##$contents2 = stream_get_contents($handle); $contents2 = ''; $contents2 .= fread($handle, 100); $contents2 = trim($contents2); This is what i get back: <br /> <b>Warning</b>: fopen($final_url) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>232</b><br /> http://www.cleanleads.co.uk/lead.aspx?campid=30&suppid=284&HSID=1121&HOID=52&FirstName=Dafydd&LastName=Thomas&AddressLine1=31 Cottage Street&Postcode=SS131HR&Gender=M&DateOfBirth=13/10/1980&emailaddress=dait@tedfsdfsdit.com&title=Mr&SupplierSourceCode=11866<br /> <b>Warning</b>: fread(): supplied argument is not a valid stream resource in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>236</b><br /> ER Any help anyone???? im lost Dear friends, I wrote a code to extract a text from a pages of a site like this: ************ $handle = @fopen($url, 'r'); $contents = ''; if ($handle) { while (!feof($handle)) { $contents .= fread($handle, 8192); } ************ This code is working properly with many pages just pages those are began with the following tags: ************ ... <body> <form name="aspnetForm" method="post" action="ViewContents.aspx?Contract=cms_Contents_I_News&amp%3br=721192" id="aspnetForm"> <input type="hidden" name="__VIEWSTATE" id=" __VIEWSTATE" value="" /> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwL+raDpAgL3qPzdCwLyp86ZD5mqDm6ZnRL/pRerpqyobvzmy5LB" /> ************ The result of function read() in variable $content is not full. It's just theme of the page without main content. I mean there isn't the story related to id of page (e.g. 721192) in the $content. Why? Is the above <form> affected the result? What can i do? Please help me. I found a script online that I am trying to get working. It was giving a 500 error from the get go and I've pinpointed it to the $data = fread() line. Does anyone know why? <?php $file = "../../media/v_360.m4v"; $filesize = filesize($file); $offset = 0; $length = $filesize; if (isset($_SERVER['HTTP_RANGE'])) { // if the HTTP_RANGE header is set we're dealing with partial content $partialContent = true; // find the requested range // this might be too simplistic, apparently the client can request // multiple ranges, which can become pretty complex, so ignore it for now preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches); $offset = intval($matches[1]); $length = intval($matches[2]) - $offset; } else { $partialContent = false; } $file = fopen($file, 'r'); // seek to the requested offset, this is 0 if it's not a partial content request fseek($file, $offset); $data = fread($file, $length); /* fclose($file); if ($partialContent) { // output the right headers for partial content header('HTTP/1.1 206 Partial Content'); header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize); } // output the regular HTTP headers header('Content-Type: ' . $ctype); header('Content-Length: ' . $filesize); header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Accept-Ranges: bytes'); // don't forget to send the data too print($data); */ ?> Its trying to read a 60mb file. Do you think it is timing out and that is causing the error? Hi All, I am trying to "echo" a result from a SQL query, that returns a size in KB, but I want this to read in MB or GB - can PHP change this for me, or is it something I need to do in SQL? Cheers Matt Would someone please take a look at this. I am trying to use a form to allow users to answer yes or no with radio buttons, and then print it out on another page. I can only get the script to print the number 1 no matter which button is selected. When I check the database the number 1 is recorded no matter which button is selected. In the top of the input form I have Code: [Select] <input type='hidden' name='electricity' value='0'>In the body of the input form I have Code: [Select] Electricity <input type='radio' name='electricity' value='0'>no <input type='radio' name='electricity' value='1'>yesAnd on the output page I have Code: [Select] $electricity = $row['electricity']; if ($electricity == 1) { $answer = "YES"; } else { $answer = "NO"; }and Code: [Select] echo $row['electricity'];I have been over and over this and can not discover my error. Thank you for looking. Hi Guys, I am trying to use htmlentities and htmlspecialchars to convert a ampersand (&) to the html markup eqivalant (&) to no avail. any ideas ? htmlentities("this is & that"); xml file: Code: [Select] <PRICES> <PRICE> <WIC>HDE0AAFGRBOX</WIC> <STOCK>100+</STOCK> <MY_PRICE>219.00</MY_PRICE> </PRICE> </PRICES>php file: Code: [Select] <? $filexml='stock.xml'; if (file_exists($filexml)) { $xml = simplexml_load_file($filexml); $f = fopen('stock.csv', 'w'); foreach($xml->PRICES->PRICE as $price) { fputcsv($f, get_object_vars($price),',','"'); } fclose($f); } ?> Error: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\stock.php on line 6 Please help with this. Hi All, I am trying to convert HTMLentities style encoding, to UTF decimal encoding. I.e. int the text: U+001D 1d <control><br /> U+007D } 7d RIGHT CURLY BRACKET<br /> U+00A2 ¢ c2 a2 CENT SIGN<br /> I want the ¢ to be its UTF decimal equivalent. that make sense?? Basically, i'm parsing text for an epub and it wont accept special characters in the html entities form - only the decimal form. Rubbish eh? The entire test text i am using is this (there is some HTML in there you see that i DO NOT want converting - basically only things between the &.. THANKS! <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Testing images</title> <link href="stylesheet.css" charset="UTF-8" type="text/css" rel="stylesheet" /> </head> <body><h2>Character Testing</h2><p align='justify'>U+0000 00 <control><br /> U+0001 01 <control><br /> U+0002 02 <control><br /> U+0003 03 <control><br /> U+0004 04 <control><br /> U+0005 05 <control><br /> U+0006 06 <control><br /> U+0007 07 <control><br /> U+0008 08 <control><br /> U+0009 09 <control><br /> U+000A 0a <control><br /> U+000B 0b <control><br /> U+000C 0c <control><br /> U+000D 0d <control><br /> U+000E 0e <control><br /> U+000F 0f <control><br /> U+0010 10 <control><br /> U+0011 11 <control><br /> U+0012 12 <control><br /> U+0013 13 <control><br /> U+0014 14 <control><br /> U+0015 15 <control><br /> U+0016 16 <control><br /> U+0017 17 <control><br /> U+0018 18 <control><br /> U+0019 19 <control><br /> U+001A 1a <control><br /> U+001B 1b <control><br /> U+001C 1c <control><br /> U+001D 1d <control><br /> U+001E 1e <control><br /> U+001F 1f <control><br /> U+0020 20 SPACE<br /> U+0021 ! 21 EXCLAMATION MARK<br /> U+0022 " 22 QUOTATION MARK<br /> U+0023 # 23 NUMBER SIGN<br /> U+0024 $ 24 DOLLAR SIGN<br /> U+0025 % 25 PERCENT SIGN<br /> U+0026 & 26 AMPERSAND<br /> U+0027 ' 27 APOSTROPHE<br /> U+0028 ( 28 LEFT PARENTHESIS<br /> U+0029 ) 29 RIGHT PARENTHESIS<br /> U+002A * 2a ASTERISK<br /> U+002B + 2b PLUS SIGN<br /> U+002C , 2c COMMA<br /> U+002D - 2d HYPHEN-MINUS<br /> U+002E . 2e FULL STOP<br /> U+002F / 2f SOLIDUS<br /> U+0030 0 30 DIGIT ZERO<br /> U+0031 1 31 DIGIT ONE<br /> U+0032 2 32 DIGIT TWO<br /> U+0033 3 33 DIGIT THREE<br /> U+0034 4 34 DIGIT FOUR<br /> U+0035 5 35 DIGIT FIVE<br /> U+0036 6 36 DIGIT SIX<br /> U+0037 7 37 DIGIT SEVEN<br /> U+0038 8 38 DIGIT EIGHT<br /> U+0039 9 39 DIGIT NINE<br /> U+003A : 3a COLON<br /> U+003B ; 3b SEMICOLON<br /> U+003C < 3c LESS-THAN SIGN<br /> U+003D = 3d EQUALS SIGN<br /> U+003E > 3e GREATER-THAN SIGN<br /> U+003F ? 3f QUESTION MARK<br /> U+0040 @ 40 COMMERCIAL AT<br /> U+0041 A 41 LATIN CAPITAL LETTER A<br /> U+0042 B 42 LATIN CAPITAL LETTER B<br /> U+0043 C 43 LATIN CAPITAL LETTER C<br /> U+0044 D 44 LATIN CAPITAL LETTER D<br /> U+0045 E 45 LATIN CAPITAL LETTER E<br /> U+0046 F 46 LATIN CAPITAL LETTER F<br /> U+0047 G 47 LATIN CAPITAL LETTER G<br /> U+0048 H 48 LATIN CAPITAL LETTER H<br /> U+0049 I 49 LATIN CAPITAL LETTER I<br /> U+004A J 4a LATIN CAPITAL LETTER J<br /> U+004B K 4b LATIN CAPITAL LETTER K<br /> U+004C L 4c LATIN CAPITAL LETTER L<br /> U+004D M 4d LATIN CAPITAL LETTER M<br /> U+004E N 4e LATIN CAPITAL LETTER N<br /> U+004F O 4f LATIN CAPITAL LETTER O<br /> U+0050 P 50 LATIN CAPITAL LETTER P<br /> U+0051 Q 51 LATIN CAPITAL LETTER Q<br /> U+0052 R 52 LATIN CAPITAL LETTER R<br /> U+0053 S 53 LATIN CAPITAL LETTER S<br /> U+0054 T 54 LATIN CAPITAL LETTER T<br /> U+0055 U 55 LATIN CAPITAL LETTER U<br /> U+0056 V 56 LATIN CAPITAL LETTER V<br /> U+0057 W 57 LATIN CAPITAL LETTER W<br /> U+0058 X 58 LATIN CAPITAL LETTER X<br /> U+0059 Y 59 LATIN CAPITAL LETTER Y<br /> U+005A Z 5a LATIN CAPITAL LETTER Z<br /> U+005B [ 5b LEFT SQUARE BRACKET<br /> U+005C \ 5c REVERSE SOLIDUS<br /> U+005D ] 5d RIGHT SQUARE BRACKET<br /> U+005E ^ 5e CIRCUMFLEX ACCENT<br /> U+005F _ 5f LOW LINE<br /> U+0060 ` 60 GRAVE ACCENT<br /> U+0061 a 61 LATIN SMALL LETTER A<br /> U+0062 b 62 LATIN SMALL LETTER B<br /> U+0063 c 63 LATIN SMALL LETTER C<br /> U+0064 d 64 LATIN SMALL LETTER D<br /> U+0065 e 65 LATIN SMALL LETTER E<br /> U+0066 f 66 LATIN SMALL LETTER F<br /> U+0067 g 67 LATIN SMALL LETTER G<br /> U+0068 h 68 LATIN SMALL LETTER H<br /> U+0069 i 69 LATIN SMALL LETTER I<br /> U+006A j 6a LATIN SMALL LETTER J<br /> U+006B k 6b LATIN SMALL LETTER K<br /> U+006C l 6c LATIN SMALL LETTER L<br /> U+006D m 6d LATIN SMALL LETTER M<br /> U+006E n 6e LATIN SMALL LETTER N<br /> U+006F o 6f LATIN SMALL LETTER O<br /> U+0070 p 70 LATIN SMALL LETTER P<br /> U+0071 q 71 LATIN SMALL LETTER Q<br /> U+0072 r 72 LATIN SMALL LETTER R<br /> U+0073 s 73 LATIN SMALL LETTER S<br /> U+0074 t 74 LATIN SMALL LETTER T<br /> U+0075 u 75 LATIN SMALL LETTER U<br /> U+0076 v 76 LATIN SMALL LETTER V<br /> U+0077 w 77 LATIN SMALL LETTER W<br /> U+0078 x 78 LATIN SMALL LETTER X<br /> U+0079 y 79 LATIN SMALL LETTER Y<br /> U+007A z 7a LATIN SMALL LETTER Z<br /> U+007B { 7b LEFT CURLY BRACKET<br /> U+007C | 7c VERTICAL LINE<br /> U+007D } 7d RIGHT CURLY BRACKET<br /> U+007E ~ 7e TILDE<br /> U+007F 7f <control><br /> U+0080 c2 80 <control><br /> U+0081 c2 81 <control><br /> U+0082 c2 82 <control><br /> U+0083 c2 83 <control><br /> U+0084 c2 84 <control><br /> U+0085 c2 85 <control><br /> U+0086 c2 86 <control><br /> U+0087 c2 87 <control><br /> U+0088 c2 88 <control><br /> U+0089 c2 89 <control><br /> U+008A c2 8a <control><br /> U+008B c2 8b <control><br /> U+008C c2 8c <control><br /> U+008D c2 8d <control><br /> U+008E c2 8e <control><br /> U+008F c2 8f <control><br /> U+0090 c2 90 <control><br /> U+0091 c2 91 <control><br /> U+0092 c2 92 <control><br /> U+0093 c2 93 <control><br /> U+0094 c2 94 <control><br /> U+0095 c2 95 <control><br /> U+0096 c2 96 <control><br /> U+0097 c2 97 <control><br /> U+0098 c2 98 <control><br /> U+0099 c2 99 <control><br /> U+009A c2 9a <control><br /> U+009B c2 9b <control><br /> U+009C c2 9c <control><br /> U+009D c2 9d <control><br /> U+009E c2 9e <control><br /> U+009F c2 9f <control><br /> U+00A0 c2 a0 NO-BREAK SPACE<br /> U+00A1 ¡ c2 a1 INVERTED EXCLAMATION MARK<br /> U+00A2 ¢ c2 a2 CENT SIGN<br /> U+00A3 £ c2 a3 POUND SIGN<br /> U+00A4 ¤ c2 a4 CURRENCY SIGN<br /> U+00A5 ¥ c2 a5 YEN SIGN<br /> U+00A6 ¦ c2 a6 BROKEN BAR<br /> U+00A7 § c2 a7 SECTION SIGN<br /> U+00A8 ¨ c2 a8 DIAERESIS<br /> U+00A9 © c2 a9 COPYRIGHT SIGN<br /> U+00AA ª c2 aa FEMININE ORDINAL INDICATOR<br /> U+00AB « c2 ab LEFT-POINTING DOUBLE ANGLE QUOTATION MARK<br /> U+00AC ¬ c2 ac NOT SIGN<br /> U+00AD c2 ad SOFT HYPHEN<br /> U+00AE ® c2 ae REGISTERED SIGN<br /> U+00AF ¯ c2 af MACRON<br /> U+00B0 ° c2 b0 DEGREE SIGN<br /> U+00B1 ± c2 b1 PLUS-MINUS SIGN<br /> U+00B2 ² c2 b2 SUPERSCRIPT TWO<br /> U+00B3 ³ c2 b3 SUPERSCRIPT THREE<br /> U+00B4 ´ c2 b4 ACUTE ACCENT<br /> U+00B5 µ c2 b5 MICRO SIGN<br /> U+00B6 ¶ c2 b6 PILCROW SIGN<br /> U+00B7 · c2 b7 MIDDLE DOT<br /> U+00B8 ¸ c2 b8 CEDILLA<br /> U+00B9 ¹ c2 b9 SUPERSCRIPT ONE<br /> U+00BA º c2 ba MASCULINE ORDINAL INDICATOR<br /> U+00BB » c2 bb RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK<br /> U+00BC ¼ c2 bc VULGAR FRACTION ONE QUARTER<br /> U+00BD ½ c2 bd VULGAR FRACTION ONE HALF<br /> U+00BE ¾ c2 be VULGAR FRACTION THREE QUARTERS<br /> U+00BF ¿ c2 bf INVERTED QUESTION MARK<br /> U+00C0 À c3 80 LATIN CAPITAL LETTER A WITH GRAVE<br /> U+00C1 Á c3 81 LATIN CAPITAL LETTER A WITH ACUTE<br /> U+00C2 Â c3 82 LATIN CAPITAL LETTER A WITH CIRCUMFLEX<br /> U+00C3 Ã c3 83 LATIN CAPITAL LETTER A WITH TILDE<br /> U+00C4 Ä c3 84 LATIN CAPITAL LETTER A WITH DIAERESIS<br /> U+00C5 Å c3 85 LATIN CAPITAL LETTER A WITH RING ABOVE<br /> U+00C6 Æ c3 86 LATIN CAPITAL LETTER AE<br /> U+00C7 Ç c3 87 LATIN CAPITAL LETTER C WITH CEDILLA<br /> U+00C8 È c3 88 LATIN CAPITAL LETTER E WITH GRAVE<br /> U+00C9 É c3 89 LATIN CAPITAL LETTER E WITH ACUTE<br /> U+00CA Ê c3 8a LATIN CAPITAL LETTER E WITH CIRCUMFLEX<br /> U+00CB Ë c3 8b LATIN CAPITAL LETTER E WITH DIAERESIS<br /> U+00CC Ì c3 8c LATIN CAPITAL LETTER I WITH GRAVE<br /> U+00CD Í c3 8d LATIN CAPITAL LETTER I WITH ACUTE<br /> U+00CE Î c3 8e LATIN CAPITAL LETTER I WITH CIRCUMFLEX<br /> U+00CF Ï c3 8f LATIN CAPITAL LETTER I WITH DIAERESIS<br /> U+00D0 Ð c3 90 LATIN CAPITAL LETTER ETH<br /> U+00D1 Ñ c3 91 LATIN CAPITAL LETTER N WITH TILDE<br /> U+00D2 Ò c3 92 LATIN CAPITAL LETTER O WITH GRAVE<br /> U+00D3 Ó c3 93 LATIN CAPITAL LETTER O WITH ACUTE<br /> U+00D4 Ô c3 94 LATIN CAPITAL LETTER O WITH CIRCUMFLEX<br /> U+00D5 Õ c3 95 LATIN CAPITAL LETTER O WITH TILDE<br /> U+00D6 Ö c3 96 LATIN CAPITAL LETTER O WITH DIAERESIS<br /> U+00D7 × c3 97 MULTIPLICATION SIGN<br /> U+00D8 Ø c3 98 LATIN CAPITAL LETTER O WITH STROKE<br /> U+00D9 Ù c3 99 LATIN CAPITAL LETTER U WITH GRAVE<br /> U+00DA Ú c3 9a LATIN CAPITAL LETTER U WITH ACUTE<br /> U+00DB Û c3 9b LATIN CAPITAL LETTER U WITH CIRCUMFLEX<br /> U+00DC Ü c3 9c LATIN CAPITAL LETTER U WITH DIAERESIS<br /> U+00DD Ý c3 9d LATIN CAPITAL LETTER Y WITH ACUTE<br /> U+00DE Þ c3 9e LATIN CAPITAL LETTER THORN<br /> U+00DF ß c3 9f LATIN SMALL LETTER SHARP S<br /> U+00E0 à c3 a0 LATIN SMALL LETTER A WITH GRAVE<br /> U+00E1 á c3 a1 LATIN SMALL LETTER A WITH ACUTE<br /> U+00E2 â c3 a2 LATIN SMALL LETTER A WITH CIRCUMFLEX<br /> U+00E3 ã c3 a3 LATIN SMALL LETTER A WITH TILDE<br /> U+00E4 ä c3 a4 LATIN SMALL LETTER A WITH DIAERESIS<br /> U+00E5 å c3 a5 LATIN SMALL LETTER A WITH RING ABOVE<br /> U+00E6 æ c3 a6 LATIN SMALL LETTER AE<br /> U+00E7 ç c3 a7 LATIN SMALL LETTER C WITH CEDILLA<br /> U+00E8 è c3 a8 LATIN SMALL LETTER E WITH GRAVE<br /> U+00E9 é c3 a9 LATIN SMALL LETTER E WITH ACUTE<br /> U+00EA ê c3 aa LATIN SMALL LETTER E WITH CIRCUMFLEX<br /> U+00EB ë c3 ab LATIN SMALL LETTER E WITH DIAERESIS<br /> U+00EC ì c3 ac LATIN SMALL LETTER I WITH GRAVE<br /> U+00ED í c3 ad LATIN SMALL LETTER I WITH ACUTE<br /> U+00EE î c3 ae LATIN SMALL LETTER I WITH CIRCUMFLEX<br /> U+00EF ï c3 af LATIN SMALL LETTER I WITH DIAERESIS<br /> U+00F0 ð c3 b0 LATIN SMALL LETTER ETH<br /> U+00F1 ñ c3 b1 LATIN SMALL LETTER N WITH TILDE<br /> U+00F2 ò c3 b2 LATIN SMALL LETTER O WITH GRAVE<br /> U+00F3 ó c3 b3 LATIN SMALL LETTER O WITH ACUTE<br /> U+00F4 ô c3 b4 LATIN SMALL LETTER O WITH CIRCUMFLEX<br /> U+00F5 õ c3 b5 LATIN SMALL LETTER O WITH TILDE<br /> U+00F6 ö c3 b6 LATIN SMALL LETTER O WITH DIAERESIS<br /> U+00F7 ÷ c3 b7 DIVISION SIGN<br /> U+00F8 ø c3 b8 LATIN SMALL LETTER O WITH STROKE<br /> U+00F9 ù c3 b9 LATIN SMALL LETTER U WITH GRAVE<br /> U+00FA ú c3 ba LATIN SMALL LETTER U WITH ACUTE<br /> U+00FB û c3 bb LATIN SMALL LETTER U WITH CIRCUMFLEX<br /> U+00FC ü c3 bc LATIN SMALL LETTER U WITH DIAERESIS<br /> U+00FD ý c3 bd LATIN SMALL LETTER Y WITH ACUTE<br /> U+00FE þ c3 be LATIN SMALL LETTER THORN<br /> U+00FF ÿ c3 bf LATIN SMALL LETTER Y WITH DIAERESIS</p> </body> </html> Hi guys, I need some help from you pro's please with converting code from a TPL template file to PHP. My client has payment gateway scripts in an ecommerce site that he wants to offer to other merchants. The code currently is in numerous TPL files (currently being used in Opencart). What is involved in converting to plain ol' PHP? Do I need the TPL files at all? Can I rename the TPL extension to PHP as it looks like they contain PHP code?? Example of one of the TPL's is below: <form action="<?php echo $action; ?>" method="post" id="checkout"> <input type="hidden" name="instId" value="<?php echo $merchant; ?>" /> <input type="hidden" name="cartId" value="<?php echo $order_id; ?>" /> <input type="hidden" name="amount" value="<?php echo $amount; ?>" /> <input type="hidden" name="currency" value="<?php echo $currency; ?>" /> <input type="hidden" name="desc" value="<?php echo $description; ?>" /> <input type="hidden" name="name" value="<?php echo $name; ?>" /> <input type="hidden" name="address" value="<?php echo $address; ?>" /> <input type="hidden" name="postcode" value="<?php echo $postcode; ?>" /> <input type="hidden" name="country" value="<?php echo $country; ?>" /> <input type="hidden" name="tel" value="<?php echo $telephone; ?>" /> <input type="hidden" name="email" value="<?php echo $email; ?>" /> <input type="hidden" name="testMode" value="<?php echo $test; ?>" /> </form> <div class="buttons"> <table> <tr> <td align="left"><a onclick="location = '<?php echo $back; ?>'" class="button"><span><?php echo $button_back; ?></span></a></td> <td align="right"><a onclick="$('#checkout').submit();" class="button"><span><?php echo $button_confirm; ?></span></a></td> </tr> </table> </div> I also have 3 PHP files as well, which look like (example): <?php class ControllerPaymentOnlineVoucher extends Controller { protected function index() { $this->data['button_confirm'] = $this->language->get('button_confirm'); $this->data['button_back'] = $this->language->get('button_back'); $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $this->load->library('encryption'); $this->data['action'] = 'https://www.domain-removed.com/purchaseAndRedeem.php'; $this->data['merchant'] = $this->config->get('onlineVoucher_merchant'); $this->data['order_id'] = $order_info['order_id']; $this->data['amount'] = $order_info['total']; $this->data['currency'] = $order_info['currency']; $this->data['description'] = $this->config->get('config_store') . ' - #' . $order_info['order_id']; $this->data['name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']; if (!$order_info['payment_address_2']) { $this->data['address'] = $order_info['payment_address_1'] . ', ' . $order_info['payment_city'] . ', ' . $order_info['payment_zone']; } else { $this->data['address'] = $order_info['payment_address_1'] . ', ' . $order_info['payment_address_2'] . ', ' . $order_info['payment_city'] . ', ' . $order_info['payment_zone']; } $this->data['postcode'] = $order_info['payment_postcode']; $payment_address = $this->customer->getAddress($this->session->data['payment_address_id']); $this->data['country'] = $payment_address['iso_code_2']; $this->data['telephone'] = $order_info['telephone']; $this->data['email'] = $order_info['email']; $this->data['test'] = $this->config->get('onlineVoucher_test'); $this->data['back'] = $this->url->https('checkout/payment'); $this->id = 'payment'; $this->template = $this->config->get('config_template') . 'payment/onlineVoucher.tpl'; $this->render(); } public function callback() { if (isset($this->request->post['callbackPW']) && ($this->request->post['callbackPW'] == $this->config->get('onlineVoucher_password'))) { $this->language->load('payment/onlineVoucher'); $this->data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); if (!isset($this->request->server['HTTPS']) || ($this->request->server['HTTPS'] != 'on')) { $this->data['base'] = HTTP_SERVER; } else { $this->data['base'] = HTTPS_SERVER; } $this->data['charset'] = $this->language->get('charset'); $this->data['language'] = $this->language->get('code'); $this->data['direction'] = $this->language->get('direction'); $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); $this->data['text_response'] = $this->language->get('text_response'); $this->data['text_success'] = $this->language->get('text_success'); $this->data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), $this->url->https('checkout/success')); $this->data['text_failure'] = $this->language->get('text_failure'); $this->data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->url->https('checkout/payment')); $this->data['button_continue'] = $this->language->get('button_continue'); if (isset($this->request->post['transStatus']) && $this->request->post['transStatus'] == 'Y') { $this->load->model('checkout/order'); $this->model_checkout_order->confirm($this->request->post['cartId'], $this->config->get('onlineVoucher_order_status_id')); $message = ''; if (isset($this->request->post['transId'])) { $message .= 'transId: ' . $this->request->post['transId'] . "\n"; } if (isset($this->request->post['transStatus'])) { $message .= 'transStatus: ' . $this->request->post['transStatus'] . "\n"; } if (isset($this->request->post['countryMatch'])) { $message .= 'countryMatch: ' . $this->request->post['countryMatch'] . "\n"; } if (isset($this->request->post['AVS'])) { $message .= 'AVS: ' . $this->request->post['AVS'] . "\n"; } if (isset($this->request->post['rawAuthCode'])) { $message .= 'rawAuthCode: ' . $this->request->post['rawAuthCode'] . "\n"; } if (isset($this->request->post['authMode'])) { $message .= 'authMode: ' . $this->request->post['authMode'] . "\n"; } if (isset($this->request->post['rawAuthMessage'])) { $message .= 'rawAuthMessage: ' . $this->request->post['rawAuthMessage'] . "\n"; } if (isset($this->request->post['wafMerchMessage'])) { $message .= 'wafMerchMessage: ' . $this->request->post['wafMerchMessage'] . "\n"; } $this->model_checkout_order->update($this->request->post['cartId'], $this->config->get('onlineVoucher_order_status_id'), $message, FALSE); $this->data['continue'] = $this->url->https('checkout/success'); $this->template = $this->config->get('config_template') . 'payment/onlineVoucher_success.tpl'; $this->render(); } else { $this->data['continue'] = $this->url->https('checkout/payment'); $this->template = $this->config->get('config_template') . 'payment/onlineVoucher_failure.tpl'; $this->render(); } } } } ?> Any guidance would be highly appreciated... Phil I am working on convering an old PHP form mail script to do error checking on the same page as the form rather then using redirects and I am having a bit of trouble with the logic. Right now it seems to work okay in general, but will send blank emails without doing the error check. Can someone please help me get it sorted out so that it works correctly. Also any ideas or input on how to make it more secure are appreciated. Thanks in advance, kaiman Here is the section of code in question: Code: [Select] // validate form if(isset($_POST['submit'])){ // check for empty form fields if (empty($name) || empty($email) || empty($category) || empty($formsubject) || empty($message)) { echo "<p>Please complete all required form fields.</p>"; } // sanitize and validate email address $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL) ; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "<p>Please enter a valid email address.</p>"; } // check for special characters in the message field and reformat if (get_magic_quotes_gpc()) { $message = stripslashes($message); } } if(isset($_POST['email'])){ // if valid send email mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\r\n" . "Reply-To: \"$name\" <$email>\n" . "X-Mailer: PHP 5.2.5" ); header( "Location: $successurl" ); } else { echo "<!-- begin form -->\n"; echo "<form name=\"Contact\" class=\"contentform\" method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\">\n"; echo "<fieldset>\n"; echo "<legend>Contact Form</legend>\n"; echo "<ol class=\"form\">\n"; echo "<li class=\"formleft\">\n"; echo "<label for=\"name\"><span class=\"asterisk\">*</span> Your Name:</label>\n"; echo "<input class=\"textfield\" id=\"name\" name=\"name\" type=\"text\" value=\"\" />\n"; echo "</li>\n"; echo "<li class=\"formright\">\n"; echo "<label for=\"email\"><span class=\"asterisk\">*</span> Email Address:</label>\n"; echo "<input class=\"textfield\" name=\"email\" type=\"text\" id=\"email\" value=\"\" />\n"; echo "</li>\n"; echo "<li class=\"formleft\">\n"; echo "<label for=\"category\"><span class=\"asterisk\">*</span> Form Category:</label>\n"; echo "<select class=\"select\" name=\"category\" id=\"category\" onchange=\"javascript:enableOther();\">\n"; echo "<option value=\"\">Please Select an Option:</option>\n"; echo "<option value=\"Question\" >Question</option>\n"; echo "<option value=\"Comment\" >Comment</option>\n"; echo "<option value=\"Idea\">Idea</option>\n"; echo "<option value=\"Other\">Other</option>\n"; echo "</select>\n"; echo "</li>\n"; echo "<li class=\"formright\">\n"; echo "<label for=\"formsubject\"><span class=\"asterisk\">*</span> Form Subject:</label>\n"; echo "<input class=\"textfield\" name=\"formsubject\" type=\"text\" id=\"formsubject\" value=\"\" />\n"; echo "</li>\n"; echo "<li>\n"; echo "<label for=\"message\"><span class=\"asterisk\">*</span> Your Message:</label>\n"; echo "<textarea name=\"message\" class=\"textarea\" rows=\"5\" cols=\"20\" id=\"message\" value=\"\"></textarea>\n"; echo "</li>\n"; echo "<li>\n"; echo "<label for=\"submitbutton\"></label>\n"; echo "<button class=\"submitbutton\" type=\"submit\" name=\"submit\" title=\"Submit\">Submit</button>\n"; echo "</li>\n"; echo "</ol>\n"; echo "</fieldset>\n"; echo "</form>\n"; echo "<!-- end form -->\n"; } OK. So, I am getting a date with the date in m/d/y format and then the hour and the minute. How can I convert this the correct way. This is what I am currently trying: Code: [Select] $started = date("Y-m-d H:i:s", strtotime($_POST['started'] . ' ' . $_POST['started_hour'] . ': ' . $_POST['started_min'])); echo $started; It give me the standard "1969-12-31 17:00:00". When all I tried was $_POST['started'], I at least got the date right. Hi All, I have a php form which is posting a country variable which is currently a number value, but before I post this to a flat text file I want to convert the number into a string (E.G. in the DB 1 = France 3=UK 6-Germany)... I was thinking something along the lines of: $Country = $_REQUEST['Country']; if ($Country =1) {$CountryW = 'France';} else if ($Country =3) {$Country = 'UK';} else if ($Country =9) {$Country = 'Test';} else {$Country = 'Germany';} But this doesn't seem to be working and there would be around 180 Countries so I can see its not efficient. Any help would be much appreciated. If you need more code let me know. Thanks so much for any help Martin Need help converting a wp theme. I got it to display the menu items, but I need it to display them in the slider like it does in the theme.
Here is a link to what the theme looks like: http://www.redfactor...rant/menu-card/
I included menucard-1.php which is the code from the theme and menu_cat_nav-1.php which my code. What am I missing?
menu_cat_nav-1.php 6.44KB
1 downloads
menucard-1.php 5.81KB
1 downloads
Hello guys,
I have been away for a couple of days. Its nice to be back
Yesterday night I was practicing an AJAX/PHP delete tutorial and file "delete.php" was wrtiten in mysql* which I converted to PDO but it didnt seem to work after conversion. The three bits of code are as follows
//I got the results using PDO::FETCH_ASSOC in following div getting ID of row in link while ($r = $getData->fetch(PDO::FETCH_ASSOC)){ echo (" <div class='record' id='record-".$r['id']."'> <a href='?delete=".$r['id']."' class='delete'>[x]</a> </div> "); } $(document).ready(function() { $('a.delete').click(function(e) { e.preventDefault(); var parent = $(this).parent(); $.ajax({ type: 'get', url: 'delete.php', data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), beforeSend: function() { parent.animate({'backgroundColor':'#fb6c6c'},300); }, success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); });and delete.php contains include "inc.connect.php"; if(isset($_GET['delete'])){ $id = $_GET['delete']; $query = "DELETE FROM tempdata WHERE id=?"; $runThis = $db->prepare($query); $runThis->bindValue(1,$id); $runThis->execute(); } /*The problem I am facing is in delete.php. because If i run the same script in mysql_*, it works, which is as follows first (I had to write connect in mysql as original connection is written in PDO) ------------------------------------------------------ $con = mysql_connect('localhost','munni****','*******'); mysql_select_db('stockcontrol',$con); if(isset($_GET['delete'])) { $result = mysql_query('DELETE FROM tempdata WHERE id = '.(int)$_GET['delete'],$con); } mysql_close($con); */ Edited by Digitizer, 11 September 2014 - 07:08 AM. I could use some help converting this HTML... Code: [Select] <textarea id="question1" name="answerArray[1]" cols="60" rows="2"><?php if (isset($answerArray[1])){echo htmlentities($answerArray[1], ENT_QUOTES);}? ></textarea> ...into PHP. This is what I have so far, but I'm getting messed up with the Sticky Form part... Code: [Select] echo '<textarea id="question' . $questionNo . '" name="qaArray[' . $questionID . ']" cols="60" rows="2"> ' . '<?php if (isset($qaArray[' . $questionID . '])){echo htmlentities($qaArray[' . $questionID . '], ENT_QUOTES);} ?></textarea>'; Thanks, Debbie |