PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Small PHP program, just learning Posted by Garrett85 on 11 Sept 2009 at 8:04 AM
In the following code I'M getting a strange output. The browser is displaying a textarea and the actual html code the for the form is inside the text area, it's strange and I can't find the problem.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Pig Latin Generator</title>
</head>

<body>

<h1>Pig Latin Generator</h1>
<?php

if($inputString == NULL)
{
	print <<<HERE
	
	<form>
	<textarea name = "inputString"
		rows = 20
		cols = 40</textarea>
	<input type = "submit"
		value = "pigify">
	</form>
HERE;
}

else
{
		//there is a value, so we'll deal with it
		// break phrase into array
	$words = split(" ", $inputString);
	
	foreach($words as $theWord)
	{
		$theWord = rtrim($theWord);
		$firstLetter = subsr($theWorld, 0, 1);
		$restOfWord = substr($theWord, 1, strlen($theWord));
			//print "$firstLetter) $restOfWord <br> \n";
		if(strstr("aeiouAEIOU", $firstLetter))
		{
				//it's a vowel
			$newWord = $theWord . "Way";
		}
		
		else
		{
				//it's a consonant
			$newWord = $restOfWord . $firstLetter . "ay";
		} // end if
		
		$newPhrase = $newPhrase . $newWord . " ";
	} // end foreach

print $newPhrase;

} // end if

?>
</body>
</html
>
Report
Re: Small PHP program, just learning Posted by rhboarder on 11 Sept 2009 at 7:19 PM
i dont know if it is the same with HEREDOCs but with strings in php if you want to use a a quotation inside a string you have to escape it so:
print <<<HERE
        <form>
        <textarea name = \"inputString\"
	      rows = 20
	      cols = 40</textarea>
        <input type = \"submit\"
	      value = \"pigify\">
        </form>
HERE;
Report
Re: Small PHP program, just learning Posted by PCoder on 12 Sept 2009 at 2:39 PM
$firstLetter = subsr($theWorld, 0, 1);

not subsr, it is substr

And use $_POST for validation.

if($inputString == NULL) to if(!$_POST) or if(!$_POST['input_name'])
Report
Re: Small PHP program, just learning(Use this code) Posted by sukh_chain on 24 Dec 2010 at 4:46 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Pig Latin Generator</title>
</head>

<body>

<h1>Pig Latin Generator</h1>
<?php
$inputString="s a s d f s d f s d f a d g f";
if($inputString == NULL)
{
print <<<HERE

<form>
<textarea name = "inputString"rows = 20 cols = 40></textarea>
<input type = "submit"
value = "pigify">
</form>
HERE;
}

else
{
//there is a value, so we'll deal with it
// break phrase into array
$words = split(" ", $inputString);

foreach($words as $theWord)
{
$theWord = rtrim($theWord);
$firstLetter = substr($theWord, 0, 1);
$restOfWord = substr($theWord, 1, strlen($theWord));
//print "$firstLetter) $restOfWord <br> \n";
if(strstr("aeiouAEIOU", $firstLetter))
{
//it's a vowel
$newWord = $theWord . "Way";
}

else
{
//it's a consonant
$newWord = $restOfWord . $firstLetter . "ay";
} // end if

$newPhrase = $newPhrase . $newWord . " ";
} // end foreach

print $newPhrase;

} // end if

?>
</body>
</html>
Report
Re: Small PHP program, just learning(Use this code) Posted by sfhdweb on 2 Jan 2011 at 11:09 PM
great program i appreciate it
Report
This post has been deleted. Posted by sfhdweb on 2 Jan 2011 at 11:05 PM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.