Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:18:02+00:00 2026-06-07T15:18:02+00:00

I have an input box that with php will echo out names typed in.

  • 0

I have an input box that with php will echo out names typed in. The problem is that when the user presses space it will echo out the blank character. I have searched and didnt find an absolute answer. I know that using !empty if there is absoutely anthing in the input field but if there is a space is null supposed to work.

How to avoid getting echo if there is blank space in input?

if (!empty($name['name']) || null ) {
    echo 'Your name is '.$name;

}
{

//do nothing 

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:18:03+00:00Added an answer on June 7, 2026 at 3:18 pm

    Calls to the function empty() will be true if it is unset, null, empty string, boolean false, or 0. Still I like avoiding heavy logic in conditionals… pull out the trimming and prepping the string before testing.

    $nameString = empty($name['name'])?null:trim($name['name']);
    if(!empty($nameString){
        //go to town here
    }
    

    To appease the fanatics in advance, I have to also add that you should escape any user input before printing it. That way you protect against XSS. To be safer add try this:

    $nameString = empty($name['name'])?null:trim($name['name']);
    $nameString = htmlentities($nameString, ENT_QUOTES);
    if(!empty($nameString){
        //go to town here
    }
    

    However, a side note… the htmlentities() call does not protect against SQL injection, so if this data is going into a db you’ll have to do more work–since your question doesn’t indicate you’re doing anything else than printing out to screen, we can hold off the SQL injection discussion for another day.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text box in an HTML form where the user will input
I have an input box that takes values from 0-100. I want to prevent
In my ASP.NET page, I have an input box that has to have the
I am want to have a input box, where a user can add or
I have a form that outputs a cookie value to a hidden input box
I have a PHP script that redirects the user to a website that they
My goal is to have input field that will take value of whats was
I have a PHP while loop that generates a table containing input tags. Each
In my form, I have a TextArea Box in which user can input multiple
I have an input box which is limited to 16 Numbers. What I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.