Unstoppable Domains

Explain this please

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
19
Code:
<?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";
?>

Okay, I am reading a tutorial and i really dont get this part and they didnt explain it either

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...
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
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
 
0
•••
still dont get it
can u explain the whole code..from start to the end and wt it means {wt its suppose to do}
 
0
•••
PHP:
<?php
//This line is appending the date with a user entered named
//i.e.: 07.28.2005|Kris
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
//This line appends the previous line with the user entered news
//the line now looks like this: 
//07.28.2005|Kris|news the user entered.
//This is another line the user entered for the news.
$line .= "|" . $HTTP_POST_VARS['news'];
//This line checks to see if the user pressed enter, and replaces it with <br>
//The line now looks like this:
//07.28.2005|Kris|news the user entered.<br>This is another line the user entered for the news.
$line = str_replace("\r\n","<BR>",$line);
/*This last line adds a new line character to the end of the string so that it is easier to read. Moves it down the next line in the source, but not on the page.*/
$line .= "\r\n";
?>


Hope this helps.
 
3
•••
okay great :D thanks
 
0
•••
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?
 
0
•••
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 B-)

Good luck

Lux
 
1
•••
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.
 
1
•••
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>";
}

k i THINK tht
foreach($data as $element)
converts all the stuff from $data to $element? am i right
 
0
•••
unknowngiver said:
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>";
}

k i THINK tht
foreach($data as $element)
converts all the stuff from $data to $element? am i right
I hope this is right.
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??
 
0
•••
yup tht makes sense :D thanks
 
0
•••
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
 
0
•••
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.');
}
}

That what you mean?
 
0
•••
Dont think so
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";
    }
}

?>
 
0
•••
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
 
0
•••
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;
        }
 
0
•••
anyone wana give it a try please
 
0
•••
You have to close two more curly brackets at the end.
 
0
•••
you missing a semi colon at the end of the first line :snaphappy:
 
0
•••
Yes!!! Amnezia wins the prize! ^_^ (Lol my post was just a test to see if it'd distract you ;))
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back