0

I am having problems with PHP I had to reinstall apache and php and MySQL and this code worked great but now that I reinstalled its giving me this error
Notice: Undefined variable: out in G:\file server\SERVER\server\admin\index.php on line 51

$title = $_POST['title'];
	$post = addslashes($_POST['text']);
	
	function nl2p($str) {
    $arr=explode("\n",$str);

    for($i=0;$i<count($arr);$i++) {
        if(strlen(trim($arr[$i]))>0)
            $out.='<p>'.trim($arr[$i]).'</p>';
    }
    return $out;
}
	$post = nl2p($post);

but this is for adding a post to a blog thing I'm trying to build however when I got to edit one with this exact same function it works. What's wrong?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by MooGeek
0

Just as error says: $out is defined in the Loop and it dies out once loop is finished.
Move it out of the loop!

$title = $_POST['title'];
	$post = addslashes($_POST['text']);
	
	function nl2p($str) {
    $arr=explode("\n",$str);
    $out="";
    for($i=0;$i<count($arr);$i++) {
        if(strlen(trim($arr[$i]))>0)
            $out.='<p>'.trim($arr[$i]).'</p>';
    }
    return $out;
}
	$post = nl2p($post);
0

It's really a big word to say "PHP is being DUMB". if PHP is being a dumb, we'll be sure not posting PHP stuffs here...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.