ereg_replace in Wordpress

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

ereg_replace in Wordpress

Post by WithHisStripes »

Heya - so I'm working on this site: http://world-of-smiles.theportlandco.com/new-patients

The site is built off Wordpress and I'm getting the pages title using Wordpress function:

Code: Select all

wp_title("", false, "")
and I'm trying to reformat it's title to all lowercase and replace spaces with dashes. It's working, except that it's adding two dashes to the beginning of the title and I'm not sure why. Can someone help?

Code: Select all

<?php echo ereg_replace(" ", "-", strtolower(wp_title("", false, ""))); ?>
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: ereg_replace in Wordpress

Post by markusn00b »

WithHisStripes wrote:Heya - so I'm working on this site: http://world-of-smiles.theportlandco.com/new-patients

The site is built off Wordpress and I'm getting the pages title using Wordpress function:

Code: Select all

wp_title("", false, "")
and I'm trying to reformat it's title to all lowercase and replace spaces with dashes. It's working, except that it's adding two dashes to the beginning of the title and I'm not sure why. Can someone help?

Code: Select all

<?php echo ereg_replace(" ", "-", strtolower(wp_title("", false, ""))); ?>
Warning: ereg_* functions are deprecated as of PHP 5.3 and removed as of PHP 6.

It sounds like your string has leading spaces. Run trim() on the string to remove them.

Code: Select all

 
ereg_replace(" ", "-", trim(strtolower(wp_title("", false, ""))));
 
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: ereg_replace in Wordpress

Post by WithHisStripes »

Awesome, that was it. Yeah I though trim() might do it but I've never used that before today. Thank you!
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: ereg_replace in Wordpress

Post by markusn00b »

WithHisStripes wrote:Awesome, that was it. Yeah I though trim() might do it but I've never used that before today. Thank you!
No problem :)
Post Reply