bbw82 Posted December 5, 2011 Share Posted December 5, 2011 I have a form where people enter in values and I need these values displayed in the proper format. I need the output string to have a "<" at the beginning and a ">" at the end but whenever I put the code in to add the < in the beginning nothing shows up. Here is my code. I am able to get it to work with just adding the > at the end but it seems when I add "<" to the beginning this is where nothing shows up. <?php $hairbald = trim($_POST['HairBald']); $eyes = trim($_POST['Eyes']); $test =$eyes.'.'.$hairbald; if(empty($test)) { $test = $test; } else $test = '<'.$test.'>'; ?> If the user selects blue eyes and bald head I need the output to be <blue.bald> Quote Link to comment https://forums.phpfreaks.com/topic/252488-trouble-getting-output-of-a-form-to-show-in-a-specific-way/ Share on other sites More sharing options...
tomfmason Posted December 5, 2011 Share Posted December 5, 2011 You don't really need to test if $test is empty and afaik your else statement should have been throwing an error. The following should work <?php $hairbald = trim($_POST['HairBald']); $eyes = trim($_POST['Eyes']); $test = '<' . $eyes.'.'.$hairbald . '>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/252488-trouble-getting-output-of-a-form-to-show-in-a-specific-way/#findComment-1294506 Share on other sites More sharing options...
bbw82 Posted December 5, 2011 Author Share Posted December 5, 2011 Same problem when using that code. I did not put this in the first post but its being displayed with echo command if that makes a difference Quote Link to comment https://forums.phpfreaks.com/topic/252488-trouble-getting-output-of-a-form-to-show-in-a-specific-way/#findComment-1294507 Share on other sites More sharing options...
kicken Posted December 5, 2011 Share Posted December 5, 2011 If your outputting to a browser, then it is going to see your construct as an HTML tag and try to render it as such. Chances are your creating an invalid tag so it just ignores it. If you want to display the < and > literally, you need to use their entities: < and >. You could either use them directly, or run your variable through the htmlentities() function when you output it. Quote Link to comment https://forums.phpfreaks.com/topic/252488-trouble-getting-output-of-a-form-to-show-in-a-specific-way/#findComment-1294511 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.