{"id":2202,"date":"2013-02-07T04:56:17","date_gmt":"2013-02-07T04:56:17","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2202"},"modified":"2013-02-07T04:56:17","modified_gmt":"2013-02-07T04:56:17","slug":"php-remove-space-from-string-how-to-remove-spaces-from-string-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-remove-space-from-string-how-to-remove-spaces-from-string-examples\/","title":{"rendered":"How To Remove Spaces From String Using PHP"},"content":{"rendered":"<p>When dealing with strings, a single space or multiple spaces could be the part of content. So at times, it might be necessary to remove this single space or remove the multiple spaces from string. So if you do not know how to remove space from string, then this article is for you. In this article, I am going to share a very easy way to use <em><strong>PHP to\u00a0<\/strong><strong>remove single space or multiple spaces from string<\/strong>\u00a0<\/em>by means of examples. So read on to find out more.<!--more--><\/p>\n<h2>Examples on using PHP to Remove Spaces 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=2202\" 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>To better illustrate <em><strong>how to remove space from string using PHP<\/strong><\/em>, let&#8217;s assume that we have some sample content and this content consists of spaces. Now we would like to remove the spaces in a single shot using PHP. So you can use the code below.<\/p>\n<h3>Example: Using PHP to remove spaces from string<\/h3>\n<pre class=\"lang:php decode:true\" title=\"Example\">&lt;?php\n\n$content = 'Hello, How are you doing today?';\n\necho 'Original Content:'; echo '&lt;br \/&gt;';\necho $content;\necho '&lt;br \/&gt;&lt;br \/&gt;';\n\n\/\/Remove all spaces from string using the function below\n$new_content = str_replace(' ', '', $content);\n\necho 'New Content:'; echo '&lt;br \/&gt;';\necho $new_content;\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=2202\" 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><strong>Simple, isn&#8217;t it?<\/strong><\/p>\n<p>Do you know of any other ways to use <em><strong>PHP to\u00a0<\/strong><strong>remove spaces from string<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When dealing with strings, a single space or multiple spaces could be the part of content. So at times, it might be necessary to remove this single space or remove the multiple spaces from string. So if you do not know how to remove space from string, then this article is for you. In this [&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":[33],"class_list":["post-2202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tips-and-tricks","category-tips-and-tricks","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-zw","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2202","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=2202"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2202\/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=2202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}