{"id":487,"date":"2023-06-24T11:42:43","date_gmt":"2023-06-24T11:42:43","guid":{"rendered":"https:\/\/www.devopsfreelancer.com\/blog\/?p=487"},"modified":"2023-06-24T11:44:16","modified_gmt":"2023-06-24T11:44:16","slug":"laravel-remove-all-spaces-from-string-example","status":"publish","type":"post","link":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/","title":{"rendered":"Laravel Remove All Spaces from String Example"},"content":{"rendered":"\n<p>In this tutorial i have to remove all spaces from string. We will look at an example of laravel remove all whitespace from string. I\u2019m going to show you about how to remove spaces from string in laravel.<\/p>\n\n\n\n<p><strong>Example 1: using str_replace()<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\n\nclass TestingController extends Controller\n{\n    public function index()\n    {\n        $string = \"Hi, This Amit Software Developer at Cotocus PVT LTD\";\n\n        $string = str_replace(' ', '', $string);\n\n        return response($string);\n    }\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Output: -<\/strong><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"421\" src=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png\" alt=\"\" class=\"wp-image-488\" srcset=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png 1024w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-300x123.png 300w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-768x316.png 768w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Example 2: using preg_replace()<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\n\nclass TestingController extends Controller\n{\n    public function index()\n    {\n        $string = \"Hi, This Amit Software Developer at Cotocus PVT LTD\";\n\n        $string = preg_replace('\/\\s+\/', '', $string);\n\n        return response($string);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:- <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"421\" src=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/image-22-1024x421.png\" alt=\"\" class=\"wp-image-489\" srcset=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/image-22-1024x421.png 1024w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/image-22-300x123.png 300w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/image-22-768x316.png 768w, https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/image-22.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial i have to remove all spaces from string. We will look at an example of laravel remove all whitespace from string. I\u2019m going to&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[174,3,173,172],"class_list":["post-487","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-how-to-use-preg_replace","tag-laravel","tag-preg_replace","tag-str_replace"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Laravel Remove All Spaces from String Example - DevOps Freelancer<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel Remove All Spaces from String Example - DevOps Freelancer\" \/>\n<meta property=\"og:description\" content=\"In this tutorial i have to remove all spaces from string. We will look at an example of laravel remove all whitespace from string. I\u2019m going to...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps Freelancer\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/amitsthakurs\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-24T11:42:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-24T11:44:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png\" \/>\n<meta name=\"author\" content=\"Amit Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/amits_thakurs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amit Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/\"},\"author\":{\"name\":\"Amit Kumar\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"headline\":\"Laravel Remove All Spaces from String Example\",\"datePublished\":\"2023-06-24T11:42:43+00:00\",\"dateModified\":\"2023-06-24T11:44:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/\"},\"wordCount\":55,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Capture-1024x421.png\",\"keywords\":[\"how-to-use-preg_replace\",\"laravel\",\"preg_replace\",\"str_replace\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/\",\"name\":\"Laravel Remove All Spaces from String Example - DevOps Freelancer\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Capture-1024x421.png\",\"datePublished\":\"2023-06-24T11:42:43+00:00\",\"dateModified\":\"2023-06-24T11:44:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Capture.png\",\"contentUrl\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/Capture.png\",\"width\":1366,\"height\":562},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/laravel-remove-all-spaces-from-string-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Laravel Remove All Spaces from String Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/\",\"name\":\"DevOps Freelancer\",\"description\":\"We provide DevOps | SRE | DevSecOps | MLOps Freelancing\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/#\\\/schema\\\/person\\\/22ed4bd82dc04200a2ca541b3e35fc5b\",\"name\":\"Amit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g\",\"caption\":\"Amit Kumar\"},\"description\":\"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\\\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/amitsthakurs\\\/\",\"https:\\\/\\\/www.instagram.com\\\/amits_thakurs\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/amits-thakurs\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/amits_thakurs\"],\"url\":\"https:\\\/\\\/www.devopsfreelancer.com\\\/blog\\\/author\\\/amit\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Laravel Remove All Spaces from String Example - DevOps Freelancer","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/","og_locale":"en_US","og_type":"article","og_title":"Laravel Remove All Spaces from String Example - DevOps Freelancer","og_description":"In this tutorial i have to remove all spaces from string. We will look at an example of laravel remove all whitespace from string. I\u2019m going to...","og_url":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/","og_site_name":"DevOps Freelancer","article_author":"https:\/\/www.facebook.com\/amitsthakurs\/","article_published_time":"2023-06-24T11:42:43+00:00","article_modified_time":"2023-06-24T11:44:16+00:00","og_image":[{"url":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png","type":"","width":"","height":""}],"author":"Amit Kumar","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/amits_thakurs","twitter_misc":{"Written by":"Amit Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#article","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/"},"author":{"name":"Amit Kumar","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"headline":"Laravel Remove All Spaces from String Example","datePublished":"2023-06-24T11:42:43+00:00","dateModified":"2023-06-24T11:44:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/"},"wordCount":55,"commentCount":1,"image":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png","keywords":["how-to-use-preg_replace","laravel","preg_replace","str_replace"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/","url":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/","name":"Laravel Remove All Spaces from String Example - DevOps Freelancer","isPartOf":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#primaryimage"},"image":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture-1024x421.png","datePublished":"2023-06-24T11:42:43+00:00","dateModified":"2023-06-24T11:44:16+00:00","author":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b"},"breadcrumb":{"@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#primaryimage","url":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture.png","contentUrl":"https:\/\/www.devopsfreelancer.com\/blog\/wp-content\/uploads\/2023\/06\/Capture.png","width":1366,"height":562},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopsfreelancer.com\/blog\/laravel-remove-all-spaces-from-string-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopsfreelancer.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Laravel Remove All Spaces from String Example"}]},{"@type":"WebSite","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#website","url":"https:\/\/www.devopsfreelancer.com\/blog\/","name":"DevOps Freelancer","description":"We provide DevOps | SRE | DevSecOps | MLOps Freelancing","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopsfreelancer.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopsfreelancer.com\/blog\/#\/schema\/person\/22ed4bd82dc04200a2ca541b3e35fc5b","name":"Amit Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d76fb4d0f15f7a458f1fd91063b44fbb7e7eb9e724b1c465d885054c2540250f?s=96&d=mm&r=g","caption":"Amit Kumar"},"description":"Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer\/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.","sameAs":["https:\/\/www.facebook.com\/amitsthakurs\/","https:\/\/www.instagram.com\/amits_thakurs\/","https:\/\/www.linkedin.com\/in\/amits-thakurs\/","https:\/\/x.com\/https:\/\/twitter.com\/amits_thakurs"],"url":"https:\/\/www.devopsfreelancer.com\/blog\/author\/amit\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/487\/revisions"}],"predecessor-version":[{"id":490,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/posts\/487\/revisions\/490"}],"wp:attachment":[{"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/media?parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/categories?post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsfreelancer.com\/blog\/wp-json\/wp\/v2\/tags?post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}