PHP - Quick Help With Small Piece Of Code!
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! Similar TutorialsMy 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>'; } } } ?> Hey guys. Im about to fail my PhP course and need help with an assignment asap. You would have to create a php login script.
If you are interested, please PM me and we'll go over details. Thanks!
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? 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?
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! 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! 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 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.
I was wondering if someone can tell me what I have done wrong with this code: <?php foreach ($row['received'] as $data) { $data += $received; } echo $received; ?> It should be adding the number 2 three times, so it should be echoing 6 but its not. Problem 1 I have is that nothing is being added to the variable $received, and problem 2 is that I suspect $received will not become 6, but rather 222. Am I correct? How do I remove the captcha check on this line and keep it valid? if ($author && $message && ($capatcha == 6 || controlPosts::isAdmin())) I tried if ($author && $message && (controlPosts::isAdmin())) but the script wont post like this? I may be on my way to a solution. Question: If the code below will scan ALL fields of my form, how can I add to the code to eliminate just one or two of the inputs, while leaving the remaining 30? $myUpdateList = array();foreach($_POST as $indexName => $value) { $myUpdateList[] = "$indexName = \"$value I have a problem with the below code: Code: [Select] <?php $sql_ranks = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date > '$last_sunday' AND vtp_tracking.action_date < '$next_sunday' GROUP BY teams.team_name ORDER BY surfs DESC"); $rsranks = mysql_query($sql_ranks); echo "<br><table align='center' valign='top' border='0' width='300px'> <tr><td colspan='2' align='center'><font size='2px'><b>Team Rankings (Current Week)</b></font></td></tr> <tr><td><font size='2px'><b>Team</font></td><td align='right'><font size='2px'>Total Surfs</font></td></tr>"; while ($row = mysql_fetch_array($rsranks)) { echo "<tr><td><font size='2px'><b>".$row[team_name]."</font></td><td align='right'><font size='2px'>".$row[surfs]."</font></td></tr>";} echo "</table>"; ?> Problem is that the last output (".$row[surfs].") is the same for all teams. It seems it is not making a total of all id's and not per team_name. anyone can see what I am doing wrong. I need to sort by team_name and the surfs should display the total of the members with team_id is ".$_GET['t']." Okay, I have no idea how this works out but this is really getting on my nerves. Here is my logic for the following code. I manually register a user, It goes into the database and dispatches an email notification explaining that a user must activate their account and change their user name (OPTIONAL) and password. In the email, There is an automatically generated password with the username, And a link to activate the account. This leads to stage 1 of the activation process, In this stage the user is accepted, Registered as a verified user and then is sent to another page to change the details like login and password. As far as I know this page works except through trial and error I found that this little snippet of code is causing browsers to show an error 500 page, If I remove this the page works: <?php if($messages){ displayErrors($messages); } else { echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>"); } ?> and this is the displayErrors function: <?php function displayErrors($messages) { print("<p align=\"center\" class=\"standard\">"."<b>There were problems with the previous action:</b>\n<ul>\n"); foreach($messages as $msg){ print("<li>$msg</li>\n"); } print("</ul>\n"."</p>"); } ?> The displayErrors function is in a file called functions.php, Which is included in config.php, Which is included in every page including this one. The entire "Change password and login page thingie" is he <?php include("config.php"); global $link, $messages; require_once('recaptchalib.php'); if($_GET['error']){ $id=$_GET['id']; $messages[]="There is more than one or no accounts with the verification code you are using. <a href=\"mailto:rentals@nivso.co.uk?subject=Two or no accounts with activation ID of $id\">Click here to email us about this and have the problem sorted.</a>"; doIndex(); exit; } if(isset($_POST['submit'])){ if(!isset($_POST['activationid'])){ die("Doesn't exist -.- might as well quit this is *STUFF* -.-"); } $privatekey = "YOUR NOT HAVING THIS"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $messages[]="The code you entered is incorrect. Please go back and try again!"; doIndex(); exit; // exit or the below lines will be processed. } else { //This is where the fun starts! $login=$_POST['login']; $passw=$_POST['password']; $passc=$_POST['passwordc']; $id2=$_POST['activationid']; $changinglogin=false; $get1=excDB("SELECT * FROM `users` WHERE `activeID`='$id2'"); if($get1[0]){ $get1=$get1[1]; } else { die($get1[2]); } $pro1=mysql_fetch_array($get1); if($pro1['login']!=$login){ $changinglogin=true; field_validator("Login", $login, "alphanumeric", 4, 15); } field_validator("Password", $passw, "string", 6, 20); if($passw!=$passc){ $messages[]="The passwords do not match, Please make sure that the passwords are the same!"; } if($messages){ doIndex(); exit; } $passcl=mysql_escape_string($passw); $passen=md5($passcl); if($changinglogin){ $wri1=excDB("UPDATE `users` SET `login`='$login', `password`='$passen', `passchange`='1', `loginchange`='1' WHERE `activeID`='$id2';"); if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); } header("Location: login.php?created"); } else { $wri1=excDB("UPDATE `users` SET `password`='$passen', `passchange`='1', `loginchange`='0' WHERE `activeID`='$id2';"); if($wri1[0]){ $wri1=$wri1[1]; } else { die($wri1[2]); } header("Location: login.php?created2"); } } } else { doIndex(); } function doIndex(){ ?> <!DOCTYPE html> <head> <title>Family Rental System! - Rent your DVDs here - Design by Alex, Coding by Gergy008</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link type="text/css" href="css/main.css" rel="stylesheet"> <style type="text/css"> <!-- body { background-color: #333333; } --> </style></head> <body style="text-align:center;"> <div class="first"> <div class="backgrounder1"></div> <div class="headerbar1"></div> <div class="headerbar2"></div> </div> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" width="900"> <tr> <td><img src="images/spacer.gif" width="52" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="123" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="352" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="33" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="55" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="110" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="50" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="15" height="1" border="0" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td colspan="9" background="images/template.slice.1.png"> </td> <td><img src="images/spacer.gif" width="1" height="20" border="0" alt="" /></td> </tr> <tr> <td colspan="5" background="images/template.slice.2.png"> </td> <td colspan="2" rowspan="2" background="images/template.slice.3.png"><span class="login"><?php echo(loginHandler()); ?></span></td> <td colspan="2" rowspan="3" background="images/template.slice.4.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td rowspan="8" background="images/template.slice.5.png"> </td> <td colspan="2" background="images/template.slice.6.png"><form> <div align="center"> <input name="textfield" type="text" id="textfield" size="40" style="height:16px;"> <input type="submit" name="button" id="button" value="Search" style="height:20px;"> </div> </form></td> <td colspan="2" rowspan="2" background="images/template.slice.7.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td colspan="2" rowspan="3" background="images/template.slice.8.png"><p> </p> <p> </p></td> <td colspan="2" background="images/template.slice.9.png"> </td> <td><img src="images/spacer.gif" width="1" height="70" border="0" alt="" /></td> </tr> <tr> <td rowspan="2" background="images/template.slice.10.png"> </td> <td colspan="4" background="images/template.slice.11.png"> </td> <td rowspan="6" background="images/template.slice.12.png"> </td> <td><img src="images/spacer.gif" width="1" height="30" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.13.png"></td> <td><img src="images/spacer.gif" width="1" height="8" border="0" alt="" /></td> </tr> <tr> <td rowspan="4" background="images/template.slice.14.png"> </td> <td colspan="4" background="images/template.slice.15.png"> </td> <td colspan="2" rowspan="4" background="images/template.slice.16.png"> </td> <td><img src="images/spacer.gif" width="1" height="35" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.17.png"> </td> <td><img src="images/spacer.gif" width="1" height="37" border="0" alt="" /></td> </tr> <tr> <td colspan="4" align="center" valign="top" background="images/template.slice.18.png" style="vertical-align:top;"><p class="standard"> </p> <table width="80%" border="0"> <tr> <td colspan="2"> <?php if($messages){ //displayErrors($messages); } else { //echo("<p align=\"center\" class=\"standard\">Your account has been activated.</p><p align=\"center\" class=\"standard\">You now need to change your password. If you like you can also change your username, Remember that you only have 3 days to do so and this change will be permanent.</p>"); ?></td> </tr> <form name="ChangeDetails" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <input type="hidden" name="activationid" value="<?php if($_GET['id']){ $id=$_GET['id']; echo($id); } elseif($_POST['activationid']){ $id=$_POST['activationid']; echo($id); } else { die("No ID") } ?>" /> <tr> <td width="50%"><div align="right" class="standard">New Username: </div></td> <td width="50%"><input name="login" type="text" id="login" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">New Password:</div></td> <td><input name="password" type="password" id="password" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">Re-enter password:</div></td> <td><input name="passwordc" type="password" id="passwordc" size="35" maxlength="30" /></td> </tr> <tr> <td><div align="right" class="standard">Please enter the code: </div></td> <td> <?php require_once('recaptchalib.php'); $publickey = "6Le4fsESAAAAAKMOHb8aaiyDfGRJyr0y0EU7dXm-"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> </td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" id="submit" value="Change your details" /></td> </tr> </form> </table> </td> <td><img src="images/spacer.gif" width="1" height="450" border="0" alt="" /></td> </tr> <tr> <td colspan="4" background="images/template.slice.19.png"> </td> <td><img src="images/spacer.gif" width="1" height="50" border="0" alt="" /></td> </tr> <tr> <td colspan="9" background="images/template.slice.20.png"> </td> <td><img src="images/spacer.gif" width="1" height="40" border="0" alt="" /></td> </tr> </table> </div> </body> </html> <?php } ?> Thanks to all you kind people that take your time to read and help me with this problem. I'm sorry if it is a really simple problem I missed out that makes me look like a right idiot and wasted your time, but that's me I'm always missing stuff out like that, I do proof read though just sometimes not good enough. Thanks in advance! Since I didn't want to type it out myself I wrote a small Date of Birth drop down menu generator. Now I'm wondering how I can make the code copy-able in a text area? The script should be inserting all the code ready and finished into a textarea so you can copy and go. How is it done? Here's the script: <?php echo "<center>"; ?> <form action='' method='POST'> <input type='submit' name='submit' /> </form> <?php $submit = $_POST['submit']; if ($submit) { echo "<form action='' method='POST'>"; echo "<select name='month'>"; for ($m = 01; $m <= 12; $m++) { echo " <option value='" . $m . "'>" . $m . "</option> "; } echo "</select>"; echo "<select name='day'>"; for ($d = 01; $d <= 31; $d++) { echo " <option value='" . $d . "'>" . $d . "</option> "; } echo "</select>"; echo "<select name='year'>"; for ($y = 1900; $y <= 2010; $y++) { echo " <option value='" . $y . "'>" . $y . "</option> "; } echo "</select>"; echo "</form>"; echo "</center>"; } ?> 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 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 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; } } 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 |