Hi folks,
I need urgent help with code here.I'm asked to create a data form that accepts odd number of words in a given sentence
Say for example,I enter "Hello my name is Jason Smith Flaunders"
The code output should be :Flaunders Smith Jason is name my Hello
It should also display the number of words.
Output:Smith Jason is name my Hello
words=7.
Can anyone help me to create the data form that outputs this? Please help me guys.Its for my univ purpose.
Thanks.
Need help with writing a php code or data form
Moderator: General Moderators
-
Blackdevil
- Forum Newbie
- Posts: 3
- Joined: Thu Nov 06, 2014 9:56 am
Re: Need help with writing a php code or data form
What have you tried so far? Where are you getting stuck?
-
Blackdevil
- Forum Newbie
- Posts: 3
- Joined: Thu Nov 06, 2014 9:56 am
Re: Need help with writing a php code or data form
I have tried using explode and then rearrange but the explode function is not properly working.So i was hoping for a solution.
Re: Need help with writing a php code or data form
How is explode not working? Care to post some code?
-
Blackdevil
- Forum Newbie
- Posts: 3
- Joined: Thu Nov 06, 2014 9:56 am
Re: Need help with writing a php code or data form
Ok.Explode is working.I had some errors so it wasnt working earlier..
I prepared a form that accepts the user data as a string.
code:
And i have the code that performs the reversal of a string
code:
I want the string entered by the user in the form to be processed and reversed so the whichever string entered will outcome with its words reversed but not the letters.So how can i do this?
I prepared a form that accepts the user data as a string.
code:
Code: Select all
<form action="welcome_get.php" method="get">
String: <input type="text" name="string"><br>
<input type="submit">
</form>code:
Code: Select all
$str = "Hello world. It's a beautiful day.";
echo "<br />\n";
echo "<br />\n";
echo"The no of words is";
echo "<br />\n";
echo str_word_count($str);
echo "<br />\n";
echo "<br />\n";
print_r (explode(" ",$str));
$a=array("$str");
$reverse=array_reverse($a);
$preserve=array_reverse($a,true);
echo "<br />\n";
echo "<br />\n";
echo implode(' ', array_reverse(explode(' ', $str)));Re: Need help with writing a php code or data form
The string you'll want to operate on, based on the structure of your form, is $_GET['string']