Creating a post page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Creating a post page

Post by Sequalit »

Im having difficulties creating a page like like the post new topic page...
where i can have the textarea also save the linebreaks (or enter button) in my sql database and then when i display the data on my front page it puts all the code nice and neat, like viewing a post...
Any help or pointers would be much apprecieated.

-SeQ
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

when displaying, you run the text through nl2br(). If you're wanting to use bbcode like tags, you'll need to dig around for some code snippets (they're all over the place) that can perform the various functions you wish to have. These are usually preparsed during storage into the database.
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Post by Sequalit »

That nl2br() thing works great... now im having trouble getting it implemented with my ereg();.. ive done some searching but cant seem to get the right combination... ive tried adding the <br> tags to the ereg() but it never see's it.. or somethings up im not quite sure.

Code: Select all

$ftype = strip_tags($ftype);
	$fdisc = strip_tags($fdisc);
	$fdisc = nl2br($fdisc);
	if(!ereg("^[A-Z a-z 0-9 ( ) , ! ? . - :]+$", $ftype)){
		echo "The type of event is incorrect, make sure you have no wierd symbols in the name.<br>";
		redirect();
		die();
	}elseif(!ereg("^[A-Z a-z 0-9 ( ) , ! ? . - : ]+$", $fdisc)){
		echo "The discription of event is incorrect, make sure you have no wierd symbols in the name.<br>";
		redirect();
		die();
	}
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Post by Sequalit »

Alright, I got it with trial and error! w00t...

It doesnt look like probably the best way to do it... but it works LOL *grin* im happy.

Code: Select all

$ftype = strip_tags($ftype);
$fdisc = strip_tags($fdisc);
$fdisc = nl2br($fdisc);
						
if(!ereg("^[A-Z a-z 0-9 ( ) , ! ? . - :]+$", $ftype)){
	echo "The type of event is incorrect, make sure you have no wierd symbols in the name.<br>";
	redirect();
	die();
}elseif(!ereg("^[A-Z a-z 0-9 ( ) , ! ? . - :]+$", $fdisc)){
	if(ereg("(\<br \/\>)",$fdisc)){
	}else{
		echo "The discription of event is incorrect, make sure you have no wierd symbols in the name.<br>";
		redirect();
		die();
	}
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the ereg functions are very slow compared to the preg functions, fyi.
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Post by Sequalit »

so would replaces ereg() with preg_match_all() be more effecient?
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Post by Sequalit »

Ok I altered my code to this, seems to work fine.

Code: Select all

$ftype = strip_tags($ftype);
$fdisc = strip_tags($fdisc);
$fdisc = nl2br($fdisc);
						
if(!preg_match("/^[A-Z a-z 0-9 ( ) , ! ? . - :]+$/", $ftype)){
	echo "The type of event is incorrect, make sure you have no wierd symbols in the name.<br>";
	redirect();
	die();
}elseif(!preg_match("/^[A-Z a-z 0-9 ( ) , ! ? . - :]+$/", $fdisc)){
	if(preg_match("/(\<br \/\>)/",$fdisc,$out)){
	}else{
	        echo "The discription of event is incorrect, make sure you have no wierd symbols in the name.<br>";
		redirect();
		die();
	}
}
Post Reply