Jump to content

Trouble getting output of a form to show in a specific way


bbw82

Recommended Posts

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>

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 . '>';
?>

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.