0

what is best solution for this replacing? fast and optimized

my link:

https://example.com/event/123/Kinda Don't Care2 Feat. Jaba/Country Music (1990)

I want clean to:

https://example.com/event/123/Kinda-Dont-Care2-Feat-Jaba/Country-Music-1990

preg_replace('???????', '-', $strUrl);

Edit:

$str1 = "Kinda Don't Care2 Feat. Jaba";

$str2 = "Country Music (1990)";

replace to :

$str1 = "Kinda-Dont-Care2-Feat-Jaba";

$str2 = "Country-Music-1990";

thanks.

1

1 Answer 1

1

try this

$string = "example.com/event/123/Kinda Don't Care2 Feat. Jaba/Country Music (1990)";

    // remove all non alphanumeric characters except spaces
    $clean =  preg_replace('/[^a-zA-Z0-9\s]/', '', strtolower($html)); 

    // replace one or multiple spaces into single dash (-)
    $clean =  preg_replace('!\s+!', '-', $clean); 

    echo $clean;

ref- Automatic clean and SEO friendly URL (slugs)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.