Home
Forums
New posts
Search forums
What's new
New posts
New resources
New profile posts
Latest activity
Resources
Latest reviews
Search resources
Members
Current visitors
New profile posts
Search profile posts
DMCA Policy
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
FEEL FREE TO SHARE TUTORIALS, YOUR SKILS & KNOWLEDGE ON CODING, SCRIPTS, THEMES, PLUGINS OR ANY RESOURCES YOU HAVE WITH THE COMMUNITY-
Click Here To Post Your Request,
JOIN COMPUTER REPAIR FORUM
Home
Forums
WEB DEVELOPMENT CODING
PHP
How to generate SEO friendly URL from string using PHP
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="codeguru" data-source="post: 3" data-attributes="member: 2"><p>In this tutorial, we’ll show you how to <strong>generate SEO friendly URL from string using PHP</strong>. Our example script makes it easy to convert title string to <strong>SEO friendly URL in PHP</strong>. We’ve grouped together all the PHP code into a function named generateSeoURL(). The generateSeoURL() function automatically create clean and SEO friendly URL slug from string.</p><h3>Create SEO Friendly URL in PHP</h3><p>The generateSeoURL() function automatically creates SEO friendly URL slug from the string using PHP. A title string needs to be passed as input and it returns a human-friendly URL string with a hyphen (-) as the word separator.</p><ul> <li data-xf-list-type="ul">$string – Required. The string which you want to convert to the SEO friendly URL.</li> <li data-xf-list-type="ul">$wordLimit – Optional. Restrict words limit on SEO URL, default is 0 (no limit)<br /> <br /> function generateSeoURL($string, $wordLimit = 0){ <br /> $separator = '-'; <br /> <br /> if($wordLimit != 0){ <br /> $wordArr = explode(' ', $string); <br /> $string = implode(' ', array_slice($wordArr, 0, $wordLimit)); <br /> } <br /> <br /> $quoteSeparator = preg_quote($separator, '#'); <br /> <br /> $trans = array( <br /> '&.+?;' => '', <br /> '[^\w\d _-]' => '', <br /> '\s+' => $separator, <br /> '('.$quoteSeparator.')+'=> $separator <br /> ); <br /> <br /> $string = strip_tags($string); <br /> foreach ($trans as $key => $val){ <br /> $string = preg_replace('#'.$key.'#iu', $val, $string); <br /> } <br /> <br /> $string = strtolower($string); <br /> <br /> return trim(trim($string, $separator)); <br /> }</li> </ul><p></p><p>Uses</p><p></p><p>Use the generateSeoURL() function to generate SEO friendly URL from title string using PHP. Provide the article title or string in the first parameter of generateSeoURL() function. If you want to restrict words on the URL, provide the number of the words otherwise can omit it.</p><p>Without Words Limit:</p><p></p><p>$postTitle = 'Generate SEO Friendly URL from String in PHP'; </p><p></p><p>$seoFriendlyURL = generateSeoURL($postTitle); </p><p></p><p>// Output will be: generate-seo-friendly-url-from-string-in-php</p><p></p><p>With Words Limit:</p><p></p><p>$postTitle = 'Generate SEO Friendly URL from String in PHP'; </p><p></p><p>$seoFriendlyURL = generateSeoURL($postTitle, 4); </p><p></p><p>// Output will be: generate-seo-friendly-url</p><p></p><p>Should you have alternative method of getting this done, kindly quote me</p></blockquote><p></p>
[QUOTE="codeguru, post: 3, member: 2"] In this tutorial, we’ll show you how to [B]generate SEO friendly URL from string using PHP[/B]. Our example script makes it easy to convert title string to [B]SEO friendly URL in PHP[/B]. We’ve grouped together all the PHP code into a function named generateSeoURL(). The generateSeoURL() function automatically create clean and SEO friendly URL slug from string. [HEADING=2]Create SEO Friendly URL in PHP[/HEADING] The generateSeoURL() function automatically creates SEO friendly URL slug from the string using PHP. A title string needs to be passed as input and it returns a human-friendly URL string with a hyphen (-) as the word separator. [LIST] [*]$string – Required. The string which you want to convert to the SEO friendly URL. [*]$wordLimit – Optional. Restrict words limit on SEO URL, default is 0 (no limit) function generateSeoURL($string, $wordLimit = 0){ $separator = '-'; if($wordLimit != 0){ $wordArr = explode(' ', $string); $string = implode(' ', array_slice($wordArr, 0, $wordLimit)); } $quoteSeparator = preg_quote($separator, '#'); $trans = array( '&.+?;' => '', '[^\w\d _-]' => '', '\s+' => $separator, '('.$quoteSeparator.')+'=> $separator ); $string = strip_tags($string); foreach ($trans as $key => $val){ $string = preg_replace('#'.$key.'#iu', $val, $string); } $string = strtolower($string); return trim(trim($string, $separator)); }[/LIST] Uses Use the generateSeoURL() function to generate SEO friendly URL from title string using PHP. Provide the article title or string in the first parameter of generateSeoURL() function. If you want to restrict words on the URL, provide the number of the words otherwise can omit it. Without Words Limit: $postTitle = 'Generate SEO Friendly URL from String in PHP'; $seoFriendlyURL = generateSeoURL($postTitle); // Output will be: generate-seo-friendly-url-from-string-in-php With Words Limit: $postTitle = 'Generate SEO Friendly URL from String in PHP'; $seoFriendlyURL = generateSeoURL($postTitle, 4); // Output will be: generate-seo-friendly-url Should you have alternative method of getting this done, kindly quote me [/QUOTE]
Insert quotes…
Verification
Post reply
Richest Freecoded User
Most Freecoin
freecoded
4,876 Freecoin
J
Johnhendrick
645 Freecoin
S
Smith16
623 Freecoin
Davy200
590 Freecoin
nathan69
426 Freecoin
Laureine
415 Freecoin
A
anajeen
395 Freecoin
P
Peterparker87
331 Freecoin
C
codeguru
282 Freecoin
Tekera
267 Freecoin
Home
Forums
WEB DEVELOPMENT CODING
PHP
How to generate SEO friendly URL from string using PHP
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top