| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Explain this pleaseCode: <?php
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
?> ????: NamePros.com http://www.namepros.com/programming/110631-explain-this-please.html y is there 4 $line variables? i thought u could only have one and y is there a "." before the "=" and whats "/r/n" etc...
__________________ |
| |
| | #2 (permalink) |
| Senior Member Join Date: Jul 2004 Location: Kizmiaz
Posts: 1,091
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | The . is appending the second part of the string to the first (which is happening twice in your example). And /r/n means line feed and carriage return (basically a new line). In this example it's replacing the line feed characters with the html equivolent '<br>'. Lux
__________________ 1 Cent Web Hosting @ Online HostGatorVoucher.com Adsense Hack for Vbulletin - Fully 3.6 Compatible ForexArea.com Free E-Course in Programming EA's |
| |
| | #4 (permalink) |
| NamePros Member Join Date: Nov 2003 Location: Ontario, Canada
Posts: 127
![]() ![]() | PHP Code: Hope this helps. |
| |
| | THREAD STARTER #6 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | okay i read it again and again but i stil dont get this part $line = str_replace("\r\n","<BR>",$line); wt is \r\n ? thts the code to see if someone pressed ENTER?
__________________ |
| |
| | #7 (permalink) |
| Senior Member Join Date: Jul 2004 Location: Kizmiaz
Posts: 1,091
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | The str_replace is a function. It replaces the first part with the second part found in the third part so... str_replace(find_this, replace_with_this, in_this). You might want to take a look at www.php.net and find some basic tutorials on Google. BTW I think eagle12 went above and beyond the call of duty with his explanation. I hope he gets some rep points for it Good luck Lux
__________________ 1 Cent Web Hosting @ Online HostGatorVoucher.com Adsense Hack for Vbulletin - Fully 3.6 Compatible ForexArea.com Free E-Course in Programming EA's |
| |
| | #8 (permalink) |
| Senior Member ![]() Join Date: Mar 2004 Location: Red State
Posts: 1,605
![]() ![]() ![]() ![]() ![]() ![]() ![]() | Spiffy little snippit. The \r\n -- in linux the \ is an escape character that says there is something special about the next character. The \r = carriage return (cr). on most systems it tlaces the cursor at the beginning of the current line but on some systems it is a cr + lf and can be frustrating when trying to build a mime email. The \n is a new line (lf). The crusor is placed on the next line at the end of the previous line. Together they place the cursor at the far left of the next line. I am not an expert but got this pounded in while writing my FormMail script. |
| |
| | THREAD STARTER #9 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Thanks guyz rep added here is a lil bit of more code tht i need help with :$ Code: foreach($data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b><BR><BR>";
} ????: NamePros.com http://www.namepros.com/showthread.php?t=110631 foreach($data as $element) converts all the stuff from $data to $element? am i right
__________________ |
| |
| | #10 (permalink) | ||||
| Senior Member ![]() Join Date: Mar 2004 Location: Red State
Posts: 1,605
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Data is an array of elements ($elements) where each element is a string like xxx|yyy|zzz. Foreach will loop through all elements. $element = trim($element); // strip any leading or trailing blanks $pieces = explode("|", $element); //Break the string $element into pieces defined by | and create an array of $pieces. the echo prints the pieces in the desired order for each element of $data. In this case zzz Posted by yyy on xxx Help?? | ||||
| |
| | THREAD STARTER #12 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | okay a little help now $password='zubair' if($HTTP_POST_VARS['submit']) { if($HTTP_POST_VARS['password'] == '$password') { here is the code now what i want is tht the script should check if the password is what i defined in "$password" .... but it gives me this error Parse error: parse error, unexpected T_IF in /home/zubair/public_html/news/addnews.php on line 13
__________________ |
| |
| | #13 (permalink) |
| DNOA Member Join Date: May 2004
Posts: 5,040
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You want to make sure that $HTTP_POST_VARS['password'] is equal to $password? Here: Code: if (isset($HTTP_POST_VARS['submit]))
{
if ($HTTP_POST_VARS['password'] != $password) {
echo('The passwords do not match.');
}
} |
| |
| | THREAD STARTER #14 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Dont think so ????: NamePros.com http://www.namepros.com/showthread.php?t=110631 here is the full code Code: $password='zubair'
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == '$password') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
} else {
echo "Bad Password";
}
}
?>
__________________ |
| |
| | #15 (permalink) |
| Senior Member Join Date: Jul 2004 Location: Kizmiaz
Posts: 1,091
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Your've got the variable $password in single quotation marks making it a string literal as in no longer a variable but the string $password. Remove them and it should be ok. Lux
__________________ 1 Cent Web Hosting @ Online HostGatorVoucher.com Adsense Hack for Vbulletin - Fully 3.6 Compatible ForexArea.com Free E-Course in Programming EA's |
| |
| | THREAD STARTER #16 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Still the same here is the code now Code: $password='zubair'
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == $password) {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
__________________ |
| |
| | #19 (permalink) |
| Professional Monkey Join Date: Jul 2005 Location: Escaped from the zoo
Posts: 907
![]() ![]() | you missing a semi colon at the end of the first line
__________________ Webmaster Words |
| |
| | #21 (permalink) | ||||
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
PHP Code: | ||||
| |
| | #24 (permalink) |
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | nvmd Just changed a couple of things.. Modified from my original post. PHP Code: |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Things you can't explain? UFOs? Ghosts? | vip-ip | The Break Room | 20 | 07-24-2005 03:51 AM |
| can someone explain me ? | saigon | Domain Newbies | 3 | 06-16-2005 05:32 AM |
| Domain Sponsors? Someone explain. | Eric | Domain Newbies | 16 | 04-04-2005 02:14 AM |
| Please Explain To Me What Parking A Domain Is!! | entrep | Domain Newbies | 3 | 11-12-2004 02:08 AM |
| Some things you just can't explain | cityit | The Break Room | 3 | 11-02-2004 01:07 PM |