{"id":177,"date":"2016-07-20T11:04:19","date_gmt":"2016-07-20T11:04:19","guid":{"rendered":"https:\/\/barkhane.com\/php\/2016\/07\/20\/php-string-functions\/"},"modified":"2024-03-03T15:04:13","modified_gmt":"2024-03-03T15:04:13","slug":"php-string-functions","status":"publish","type":"post","link":"https:\/\/barkhane.com\/php\/php-string-functions\/","title":{"rendered":"PHP String Functions"},"content":{"rendered":"<h2>What are String in PHP?<\/h2>\n<p>A string is a Collection\u00a0of characters Putting together. In <a href=\"https:\/\/barkhane.com\/php\/what-is-php\/\" target=\"_blank\" rel=\"noopener\">PHP <\/a>string can be a collection of numbers or\u00a0alphabets\u00a0nor a mixture of number and alphabets.String is Enclosed with in the <strong>\\&#8221; \\&#8221;.\u00a0<\/strong><\/p>\n<p>In PHP string has a wide role to play ,You can work on various way with the string in PHP .<\/p>\n<p><strong>Where the String Stored ?<\/strong><\/p>\n<p>String Store in variable like $str= \\&#8221;Name of book\\&#8221;;<\/p>\n<p>There are various way to deal with string.Some important and useful \u00a0string \u00a0function of PHP are give below<\/p>\n<pre><code> \n\/\/\/ Assume $str=\\\"PHP is Simple\\\";\n\n<strong>\/\/ How to count the length of string ?<\/strong>\n \n$l=strlen($str);\n\necho\\\"Number of charater in Variable string \u00a0$str are $l\\\";\n\n\/\/Output:13\n  \n<strong>\/\/How to convert string into upper case?<\/strong>\n\n$stu=strtoupper(#str);\n\necho $stu;\n\n\/\/Output:PHP IS SIMPLE\n\n<strong>\/\/How to convert string into lower\u00a0case?<\/strong>\n\n$stl=strtolower(#str);\n\necho $stl;\n\n\/\/Output:php is simple\n\n<strong>\/\/How to Copy string?<\/strong>\n\n$cpy=$str;\n\necho $cpy;\n\n\/\/Output:PHP is Simple\n\n<strong>\/\/How to merge Two string?<\/strong>\n\n$addstr=\\\"and easy\\\";\n\n$merge= $str .$addstr;\n\necho $merge;\n\n\/\/ Output:PHP is Simple and easy\n\n<strong>\/\/ How to reverse a string ?<\/strong>\n\n$a=hello;\n\n$b=strrev($a);\n\necho $b;\n\n\/\/ Output: olleh\n\n<strong>\/\/ How to Break A string ?<\/strong>\n\n$char=\\\" \\\";\n\n$result = strpbrk($str, $char);\n\necho\u00a0$result;\n\n\/\/ Output:\u00a0PHP\n <\/code><\/pre>\n<p>Note :this function breaks a string from specified charter if found ,it search for the first instance of character in string , in above example it is space .<\/p>\n<p><strong>How to Replace Text Within a String ?<\/strong><\/p>\n<pre><code>\n$newstr =str_replace(\\\"Simple\\\", \\\"easy\\\",$str);\n\nOutputs:\u00a0PHP is easy;\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are String in PHP? A string is a Collection\u00a0of characters Putting together. In PHP string can be a collection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","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-177","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/177","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=177"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/posts\/177\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/media?parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/categories?post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/php\/wp-json\/wp\/v2\/tags?post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}