0

I'm currently using this to give me a title based on the current URL:

<?php $url = $_SERVER["REQUEST_URI"]; 
echo"$url"; 
$url = trim ( $url ,'/' ); ?>
<title>mysite.com - <?php echo $url; ?></title>

Many of my urls are formatted like this:

mysite.com - 177_183_45_999

Is it possible to replace the underscores with hyphens? to acheive:

mysite.com - 177-183-45-999

thanks

2 Answers 2

1

Use str_replace:

str_replace("_", "-", $url)

Example:

<?php echo str_replace("_", "-", $url); ?>

Or for a sexy oneliner:

$url = str_replace("_", "-", trim($_SERVER["REQUEST_URI"], "/")); 
1

Use str_replace:

$url = str_replace('_', '-', $url);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.