{"flag":true,"single":true,"pageTitle":"convert title to slug in php | sanitize_title() in php","post":{"id":36,"user_id":"1","slug":"convert-title-to-slug-in-php-sanitize-title-in-php-nnwq","title":"convert title to slug in php | sanitize_title() in php","body":"<p>Example&nbsp; to convert title to slug in php<\/p>\r\n<pre class=\"language-markup\"><code>$title = \"This is a Sample Title!\";\r\n$slug = sanitize_title($title);\r\necho $slug; \/\/ Outputs: \"this-is-a-sample-title\"<\/code><\/pre>\r\n<p>Function defination \/explaination<\/p>\r\n<pre class=\"language-markup\"><code>&lt;?php\r\nfunction sanitize_title($title) {\r\n  $title = strip_tags($title); \/\/ remove HTML and PHP tags\r\n  $title = preg_replace('\/[\\r\\n\\t ]+\/', ' ', $title); \/\/ replace new lines, tabs, and multiple spaces with a single space\r\n  $title = trim($title); \/\/ remove leading and trailing spaces\r\n  $title = strtolower($title); \/\/ convert to lowercase\r\n  $title = preg_replace('\/[^a-z0-9\\-]\/', '', $title); \/\/ remove anything that is not a lowercase letter, number, or hyphen\r\n  $title = preg_replace('\/-+\/', '-', $title); \/\/ replace multiple hyphens with a single one\r\n  return $title;\r\n}\r\n?&gt;<\/code><\/pre>","category_id":"1","is_private":"0","created_at":"2023-03-21T09:27:37.000000Z","updated_at":"2023-03-21T09:27:37.000000Z","category":{"id":1,"user_id":"1","name":"PHP","slug":"php-3ius","parent_id":null,"created_at":"2023-03-14T03:58:19.000000Z","updated_at":"2023-03-14T03:58:19.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"Example&nbsp; to convert title to slug in php $title = \"This is a Sample Title!\"; $slug = sanitize_title($title); echo $slug; \/\/ Outputs: \"t - convert title to slug in php | sanitize_title() in php (Updated: March 21, 2023) - Read more about convert title to slug in php | sanitize_title() in php at my programming site [SITE]","categories":[]}