Need an advise/ help on string

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
User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

Need an advise/ help on string

Post by raymedia »

i have a form..

and when i proccess the form, it need to check if there is ' or " character in it..

and most important bit here is all " need to be changed to '

i tried str_replace, preg_replace but theres syntax error. can anyone help me pls

thanks a lot for your time
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your code.
wasabi
Forum Newbie
Posts: 17
Joined: Sat Sep 04, 2004 9:38 am
Location: Adelaide

Post by wasabi »

This Small section of code might help....

Code: Select all

<?PHP if (!eregi("^[0-9]{4}", $_POST['number1']) || !eregi("^[0-9]{4}", $_POST['number2']) || !eregi("^[0-9]{4}", $_POST['number3']) || !eregi("^[0-9]{4}", $_POST['number4']))
	{
		$nonumber= "Invalid <b>credit card number</b><br />";
		$error .= $nonumber;
		$errorValue = 1;
	}?>
This section converts the credit card number to ****-****-****-0000

Code: Select all

<?PHP		 $num1 = ereg_replace("^[0-9]+$", "****", $_POST['number1']);
		 $num2 = ereg_replace("^[0-9]+$", "****", $_POST['number2']);
		 $num3 = ereg_replace("^[0-9]+$", "****", $_POST['number3']);
		 $adjust = $num1;
		 $adjust .= " - ". $num2 ." - ". $num3 ." - ". $_POST['number4']; ?>
and check if the @ . was included in an email address

Code: Select all

<?PHP if (!eregi("^[''+\\./0-9A-Z^_\`a-z{|}~\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){1,3}$", $_POST['email']))
	{
		$noemail = "Invalid <b>Email Address</b><br />";
		$error .= $noemail;
		$errorValue = 1;
	}
?>

Hope this helps in some way.
Post Reply