Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Coding/Programming Interviews:Active Template Library (ATL)ActiveXApplication DeveloperArtificial intelligenceAssemblyAssociate Software EngineerAWKAWTC ProgrammingC++ ProgrammingCGI PerlCGI ProgrammingCMMICobolCritical ReasoningData Structures TreesDCOM COMDelphiDTDE4XExtensible Stylesheet Language (XSL)FortranFull-Stack DeveloperHaskellHTML DOMILUIPhone DeveloperJasper Reports DeveloperJava DeveloperLisp ProgrammingLotus NotesMicrosoft Foundation Class (MFC)Mobile DeveloperMVC DeveloperNode.jsOOPPascalPerl ProgrammingPHPPHP DeveloperProgrammingProgramming AlgorithmsProgramming ConceptsPythonRubyRuby on RailsRuby on Rails DeveloperSenior Front End DeveloperSenior Software DeveloperSignature ProgramSOASocket ProgrammingSoftware Development EngineerSoftware engineeringSr. PHP ProgrammerStack And QueueSTLSwift DeveloperTCL (Tool Command Language)Team Leader Android DeveloperUMLUnity 2D Games DeveloperUnity 3D DeveloperUnity DeveloperVBA (Visual Basic for Applications)Visual Basic (VB)Visual C++Web DevelopmentWin32APIWindows ProgramingWordPress DevelopmentWSDLXFormsXHTMLXLinkXMLXPathXQueryXSL-FOXSLT
Copyright © 2018. All Rights Reserved
PHP Interview Question:
How To Remove White Spaces from the Beginning and/or the End of a String in PHP?
Submitted by: AdministratorThere are 4 PHP functions you can use remove white space characters from the beginning and/or the end of a string:
► trim() - Remove white space characters from the beginning and the end of a string.
► ltrim() - Remove white space characters from the beginning of a string.
► rtrim() - Remove white space characters from the end of a string.
► chop() - Same as rtrim().
White space characters are defined as:
► " " (ASCII 32 (0x20)), an ordinary space.
► " " (ASCII 9 (0x09)), a tab.
► " " (ASCII 10 (0x0A)), a new line (line feed).
► " " (ASCII 13 (0x0D)), a carriage return.
► " " (ASCII 0 (0x00)), the NULL-byte.
► "x0B" (ASCII 11 (0x0B)), a vertical tab.
Here is a PHP script example of trimming strings:
<?php
$text = " Hello world! ";
$leftTrimmed = ltrim($text);
$rightTrimmed = rtrim($text);
$bothTrimmed = trim($text);
print("leftTrimmed = ($leftTrimmed) ");
print("rightTrimmed = ($rightTrimmed) ");
print("bothTrimmed = ($bothTrimmed) ");
?>
This script will print:
<pre>leftTrimmed = (Hello world! )
rightTrimmed = ( Hello world!)
bothTrimmed = (Hello world!)</pre>
Submitted by: Administrator
► trim() - Remove white space characters from the beginning and the end of a string.
► ltrim() - Remove white space characters from the beginning of a string.
► rtrim() - Remove white space characters from the end of a string.
► chop() - Same as rtrim().
White space characters are defined as:
► " " (ASCII 32 (0x20)), an ordinary space.
► " " (ASCII 9 (0x09)), a tab.
► " " (ASCII 10 (0x0A)), a new line (line feed).
► " " (ASCII 13 (0x0D)), a carriage return.
► " " (ASCII 0 (0x00)), the NULL-byte.
► "x0B" (ASCII 11 (0x0B)), a vertical tab.
Here is a PHP script example of trimming strings:
<?php
$text = " Hello world! ";
$leftTrimmed = ltrim($text);
$rightTrimmed = rtrim($text);
$bothTrimmed = trim($text);
print("leftTrimmed = ($leftTrimmed) ");
print("rightTrimmed = ($rightTrimmed) ");
print("bothTrimmed = ($bothTrimmed) ");
?>
This script will print:
<pre>leftTrimmed = (Hello world! )
rightTrimmed = ( Hello world!)
bothTrimmed = (Hello world!)</pre>
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.