Sandra Posted January 9, 2020 Share Posted January 9, 2020 Hello all, I'm a basic coder 😀 I want to insert a line break in this code, after the {hobby:value} it gives me : syntax error, unexpected '>' if($_POST['form']['hobby'] == '')  $modUserEmailText = str_replace('{hobby:caption} : {hobby:value}', ''<br/>'',$modUserEmailText); {hobby:caption} : {hobby:value} are placeholders in the sent email, since there are several of them, all I want is a line break between each.. and must end with $modUserEmailText); is this possible to do? {hobby:caption} : {hobby:value} {age:caption} : {age:value} {book:caption} : {book:value} Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/ Share on other sites More sharing options...
requinix Posted January 9, 2020 Share Posted January 9, 2020 I take it you've seen " before but never typed it out until now? That there is (supposed to be) a double quote, not two single quotes. Shift + ' Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573193 Share on other sites More sharing options...
Sandra Posted January 9, 2020 Author Share Posted January 9, 2020 I have tried the single quote and the double quote, in different places... many many tests.. before I came asking for help Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573194 Share on other sites More sharing options...
requinix Posted January 9, 2020 Share Posted January 9, 2020 Well, all I can really do is tell you about the problems you post here, and this current one is because you're typing two apostrophes in the place of one quotation mark. If you still have problems after fixing that then we'll deal with them. But you'll have to describe them. Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573195 Share on other sites More sharing options...
Sandra Posted January 9, 2020 Author Share Posted January 9, 2020 if you guys had to put a line break in this code, how does it go? cheers if($_POST['form']['age'] != '') $modAdminEmailText .= '{age:caption}: {age:value}'; Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573204 Share on other sites More sharing options...
cyberRobot Posted January 9, 2020 Share Posted January 9, 2020 55 minutes ago, Sandra said: if you guys had to put a line break in this code, how does it go? Perhaps the link below will help. Note the first example on the page.https://www.php.net/manual/en/control-structures.if.php Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573206 Share on other sites More sharing options...
Barand Posted January 9, 2020 Share Posted January 9, 2020 1 hour ago, Sandra said: how does it go? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573208 Share on other sites More sharing options...
Sandra Posted January 9, 2020 Author Share Posted January 9, 2020 I've tried this, still no change, but does not give me errors if($_POST['form']['hobby'] != '') echo "<br />"; $modUserEmailText .= '{hobby:caption} : {hobby:value}'; This one gives me an error : syntax error, unexpected ',' if($_POST['form']['hobby'] != '') $modUserEmailText .= '{hobby:caption} : {hobby:value}'."\r\n"; any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573210 Share on other sites More sharing options...
requinix Posted January 9, 2020 Share Posted January 9, 2020 7 hours ago, Sandra said: This one gives me an error : syntax error, unexpected ',' if($_POST['form']['hobby'] != '') $modUserEmailText .= '{hobby:caption} : {hobby:value}'."\r\n"; The error is complaining about a comma in the code. There is no comma in that code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573223 Share on other sites More sharing options...
ginerjm Posted January 9, 2020 Share Posted January 9, 2020 Can you use the <> code icon to open up a window and then do a copy and paste from your editor into that code window so that we can see the real code you are running? Not all of it - just the part you are questioning. Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573225 Share on other sites More sharing options...
gizmola Posted January 9, 2020 Share Posted January 9, 2020 With most of these examples you are omitting blocks. Here is a block: { //Something } Many languages use the {} to denote a block. There are others that use something different, or use indentation (most notably python), but PHP is not one of those languages. Let's go back to an example you gave (Indentation mine):  if($_POST['form']['hobby'] != '') echo "<br />"; $modUserEmailText .= '{hobby:caption} : {hobby:value}'; After your condition ($_POST['form']['hobby'] != '') You do not have a start block. So only the next line will be executed if the condition is true. I don't think that is what you expect.  So you need a block around ALL the code that will execute if the condition is true: if($_POST['form']['hobby'] != '') {   echo "<br />";   $modUserEmailText .= '{hobby:caption} : {hobby:value}'; }  Obviously you are not giving us real code or are giving us snippets of the code as the errors don't correlate to the code you've provided, but perhaps this explanation will help you out. Just for completeness: if (!empty($_POST['form']['hobby']) {   echo "<br />";   $modUserEmailText .= '{hobby:caption} : {hobby:value}' } This would be the proper way to handle the condition you are checking for. The problem with the code you presented, is that it will provide a runtime error if the $_POST['form']['hobby'] element does not exist. For things like checkboxes, this is a common occurrence. empty checks that the variable exists (isset) AND that it has a value (!= '''); You might also want to trim the value, as even a space would pass through your check and empty. Quote Link to comment https://forums.phpfreaks.com/topic/309809-help-a-newbie-please/#findComment-1573231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.