Jump to content

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


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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.