Solved

convert to lowercase & change spaces to hyphen

Posted on 2011-09-23
6
606 Views
Last Modified: 2012-06-27
How do I convert the below to lowercase and change all spaces to a hyphen?

$row_rs_wp_posts['post_title']
0
Comment
Question by:petewinter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
dsmile earned 375 total points
ID: 36585992

$row_rs_wp_posts['post_title'] = str_replace(' ', '-', strtolower($row_rs_wp_posts['post_title']));

Open in new window

0
 
LVL 13

Assisted Solution

by:dsmile
dsmile earned 375 total points
ID: 36586001
strtolower() changes string to lower case.
str_replace() replaces first param by second param
0
 

Author Comment

by:petewinter
ID: 36586047
Thanks. Sorry I also need it to remove any special characters like & ,etc. How can I do this?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 13

Assisted Solution

by:dsmile
dsmile earned 375 total points
ID: 36586100
Simple approach: add characters you want to replace in $arySearch, and '-' to $aryReplace (number of elements must be equal)


$row_rs_wp_posts['post_title'] = strtolower($row_rs_wp_posts['post_title']); //convert string to lower
$arySearch = array(' ', '&');
$aryReplace = array('-', '-');
$row_rs_wp_posts['post_title'] = str_replace($arySearch, $aryReplace, $row_rs_wp_posts['post_title']); //replace characters

Open in new window


Advanced way: read about preg_replace and use it for replacing work
0
 
LVL 3

Assisted Solution

by:FrankoH
FrankoH earned 125 total points
ID: 36586106
here is a small function i use to clean up urls, it should do the trick, just remove/add characters to suit.

function UrlSafeString( $strVal ) {
	
		// Replaces illegal url characters with a safe alternative
			
		$strSearch = array( '"',"'", "?", " ", "/", "\\", "@", "=", "|", "+", "(", ")", "[", "]", "{", "}", "*",   "&", "#", "!", "." );
		$strReplace = array("" , "",  "", "-", "-",  "-", "-", "-", "-", "-",  "",  "",  "",  "",  "",  "",  "",  "and",  "",  "",  "" );
	
		return str_replace($strSearch, $strReplace, strtolower($strVal) );
		
		}

Open in new window

0
 

Author Closing Comment

by:petewinter
ID: 36586183
Many thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Link failure 16 71
Wordpress Query 5 47
Change a button after e-mail 4 23
Could you point what's preventing a remote MySQL server to be accessed? 8 45
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question