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!
I was hoping someone could help me. I am trying to build a simple form that concatenates. The issue I have is trying to get the words entered into an array that then spits out the result into the same page. I have managed to do some simple concatenation with just one or 2 words, but now I am entering the realms of an array and I'm not sure whats next.
<?php
$total=$_POST["textarea"]
$keyarr=explode("\n",$total);
// In order to process this array values here is the code
foreach($keyarr as $key=>$value)
{
echo "$all_keywords<br />";
echo "\"$all_keywords\"<br/>";
echo "[$all_keywords]<br />";
}
?>
Ideally I want the results to appear in the same text area concatenated with the users choice. At the moment it just goes to a blank page. I am a newb so I am prob missing something important!
1. You have an error in PHP code in line 1. You forgot about ; at the end of the line.
2. If you don't get an error message, you should examine your error reporting level. I suggest reading this: http://www.phperrorfix.com/5/i-can-t-se ... r-messages
3. You forgot to close textarea tag.
4. You are closing form tag before texatera, so texatera don't exists in your form.
5. At last, I'm not sure what do you want to do, I fixed your code and simplify it a bit. Read it and maybe this will help you:
That's great thanks ever so much for your help. I want to create something like this http://www.jumbokeyword.com
when you enter the keywords, and select one of the buttons to the left it spits out the result into the same window. I need to now somehow send the results to the same place. I can see the jumbokeyword uses Ajax. Presumably this is how they are achieving that? Is it simply a case of putting the foreach statement into the right part of the page?
I did two sample buttons for you, but inserting the result to textarea may be bit more complicated. Your sample site is using AJAX for that but it is also achiveable only with PHP.
Ok I have tried moving on from this towards including another text area for multipliers and concatenating them. However I'm not sure how to construct the php elements.
So for example you were to write in the first box the word new, and in the second box the word clothes, and pressed the exact match button, you would end up with [new clothes]
The issue I have (i think)is sending two lots of isset POST . I'm sure this is quite simple but I can't seem to fathom it out! Any help would be greatly appreciated!
You can't do it in this way. You have to give different names for your different variables, otherwise the second declaration will overwrite the first. Second thing is that your foreach(...) and (...) will cause Parse error, there is no such thing in PHP. Try this code, it should give you some ideas:
SO in essence, the if statement would read: "if the first box has something and the second box has something, concatenate them depending on the users choice (phrase, exact etc), otherwise just return the first box contents as per the users choice.
This is ok, but handling data may be more complicated problem: how to validate data in textareas: if empty second textarea, if empty first textarea, if different number of lines in both textareas and so on...
Ok I see what you mean. This is almost there though, I just need to get it so that if i add more than one keyword in the first textarea, the multiplier concatenates against each word. At the moment it adds it to the first one only.
I'm assuming this is to do with the counter variable? Also if no words are added to the second text area the result is [clothes ]. I need to strip that extra space before the closing bracket? I believe this is the trim function, and I have tried this to no avail?
Just realised that it probably is stripping it, just the end of the string is after the closing ] whereas I need to strip whitespace before the closing ].
Hmm...would i need to count the characters and the strip the one before the end?
1. Yes, you should expand this code for each type of match.
2. I can't tell why isset($_POST['exact']) does not work because I don't see the whole code. Maybe something is wrong in HTML name=""...
3. I also can't tell why your code breaks after moving PHP lower in the code, you may paste whole broken code here.