{"id":2207,"date":"2013-02-07T05:13:20","date_gmt":"2013-02-07T05:13:20","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2207"},"modified":"2013-02-07T05:13:20","modified_gmt":"2013-02-07T05:13:20","slug":"php-remove-whitespace-from-string-how-to-remove-whitespaces-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-remove-whitespace-from-string-how-to-remove-whitespaces-examples\/","title":{"rendered":"How To Remove Whitespaces Using PHP &#8211; Examples"},"content":{"rendered":"<p>If you have read my previous article on <a title=\"PHP Remove Space From String | How To Remove Spaces From String Examples\" href=\"https:\/\/theextremewebdesigns.com\/blog\/php-remove-space-from-string-how-to-remove-spaces-from-string-examples\/\" target=\"_blank\">how to remove spaces from string<\/a>, then you would be interested in this article too. In general terms, space is nothing but a gap between two words whereas a &#8220;<strong>whitespace<\/strong>&#8221; could be a tab, a space, \u00a0a line feed or a carriage return. The procedure to remove whitespaces from string is a bit different from the procedure to remove spaces from string. In this article, I am going to share a very easy way to use <em><strong>PHP to remove whitespaces from strings<\/strong><\/em>\u00a0by means of examples.<\/p>\n<p><!--more--><\/p>\n<h2>Examples On Using PHP To Remove Whitespace From String<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2207\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>In order to see <strong>&#8220;<em>how to remove white spaces from string using PHP<\/em>&#8220;<\/strong>, let&#8217;s assume that we have some sample string and it contains spaces, tabs, carriage returns, etc. We will now remove these white spaces from this string.<\/p>\n<h3>Example: Using PHP to remove white spaces from string<\/h3>\n<pre class=\"lang:php decode:true\" title=\"Example\">&lt;?php\n\n$content = \"Hello, How are you doing today?\t\tOk ---    I am going \t\t...GREAT!!! \n\nHow about yourself?\n\";\n\necho 'Original Content:'; echo '&lt;br \/&gt;';\necho '&lt;pre&gt;'.$content.'&lt;\/pre&gt;';\necho '&lt;br \/&gt;';\n\n\/\/Remove all whitespaces from string using the function below\n$new_content = preg_replace('\/\\s+\/', '', $content);\n\necho 'New Content:'; echo '&lt;br \/&gt;';\necho '&lt;pre&gt;'.$new_content.'&lt;\/pre&gt;';\necho '&lt;br \/&gt;';\n\n?&gt;<\/pre>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2207\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>That&#8217;s it!<\/h5>\n<p>Do you know of any other ways to <strong>remove whitespace from string using PHP<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have read my previous article on how to remove spaces from string, then you would be interested in this article too. In general terms, space is nothing but a gap between two words whereas a &#8220;whitespace&#8221; could be a tab, a space, \u00a0a line feed or a carriage return. The procedure to remove [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,13],"tags":[125,33],"class_list":["post-2207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tips-and-tricks","category-tips-and-tricks","tag-php-demos-2","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-zB","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=2207"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2207\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=2207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}