{"id":187,"date":"2016-07-27T14:38:12","date_gmt":"2016-07-27T14:38:12","guid":{"rendered":"https:\/\/barkhane.com\/php\/2016\/07\/27\/php-trim\/"},"modified":"2024-03-03T15:04:11","modified_gmt":"2024-03-03T15:04:11","slug":"php-trim","status":"publish","type":"post","link":"https:\/\/barkhane.com\/php\/php-trim\/","title":{"rendered":"PHP trim"},"content":{"rendered":"<h2>What is trim \u00a0in PHP?<\/h2>\n<p><strong>trim()<\/strong> function in <a href=\"https:\/\/barkhane.com\/php\/what-is-php\/\" target=\"_blank\" rel=\"noopener\">PHP<\/a> \u00a0removes whitespace \u00a0from both sides of a string. <strong>trim()<\/strong> function also removes\u00a0other predefined characters from the string. Genrally we use trim function where we require zero error like in the case of user id or email or password in which a whitespace can change the whole thing.There are two other function with some where Works like Trim function there are<\/p>\n<ul>\n<li>ltrim()<\/li>\n<li>rtrim()<\/li>\n<\/ul>\n<p>Trim function can use to eliminate desired string or charter in <a href=\"https:\/\/barkhane.com\/php\/what-is-php\/\" target=\"_blank\" rel=\"noopener\">PHP <\/a><a href=\"https:\/\/barkhane.com\/php\/php-string-functions\/\" target=\"_blank\" rel=\"noopener\">string \u00a0<\/a>for example<\/p>\n<p>Here $str is a <a href=\"https:\/\/barkhane.com\/php\/what-is-php\/\" target=\"_blank\" rel=\"noopener\">PHP <\/a>variable which stores <a href=\"https:\/\/barkhane.com\/php\/php-string-functions\/\" target=\"_blank\" rel=\"noopener\">string \u00a0<\/a>.<\/p>\n<pre><code>  \n\n&lt;?php\n$str = \\\"whatwhyhow\\\";\necho trim($str,\\\"w\\\");\n?&gt;\n   <\/code><\/pre>\n<p>Output will be <strong>hathyow<\/strong><\/p>\n<h2>What is LTRIM?<\/h2>\n<p>ltrim() works like trim function the difference is ltrim removes only\u00a0whitespace from left side of string. there is no other difference between TRIM and LTRIM function .<\/p>\n<p>&nbsp;<\/p>\n<h2>What is RTRIM?<\/h2>\n<p>rtrim() works like trim function the difference is rtrim removes only\u00a0whitespace from right\u00a0side of string. there is no other difference between TRIM and RTRIM function .<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is trim \u00a0in PHP? trim() function in PHP \u00a0removes whitespace \u00a0from both sides of a string. trim() function also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}