php

PHP – Remove spaces at the beginning and end of a string

In this tutorial, we are going to see how to remove spaces at the beginning and end of a string in PHP. You can use trim() function in PHP to remove spaces, including newlines and tabs at the beginning and end of a string. Spaces will not be removed in the middle of a string. Here is an example:
 

Remove spaces at the beginning and end of a string in PHP
<?php
	$str = '    Welcome to StackHowTo     ';
	$new_str = trim($str);
	echo $new_str;
?>

Output:

Welcome to StackHowTo
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *