Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

string parser

Posted on 2006-11-23
6
Medium Priority
?
245 Views
Last Modified: 2006-11-23
How can I replace everything that is not a-z0-9 in a string with "" and " " with "-"

Thank you in advance
0
Comment
Question by:brightwood
[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
  • 3
6 Comments
 
LVL 17

Expert Comment

by:HuyBD
ID: 18005429
$newstring=ereg_replace('\"[a-z0-9]\"', $string,
                  '-');
0
 

Author Comment

by:brightwood
ID: 18005448
I don't think I explained it good enough.
I want to:
1. replace " " with "-"
2. replace every character that is not letter, number, or "-" with ""
0
 

Author Comment

by:brightwood
ID: 18005456
For example, "test 2.%a" should become "test-2a"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:HuyBD
ID: 18005526

$newstring=ereg_replace('[^a-zA-Z0-9]','', $string);
0
 
LVL 17

Accepted Solution

by:
HuyBD earned 2000 total points
ID: 18005576
sorry

$newstring=ereg_replace('[^a-zA-Z0-9-]','',ereg_replace(' ','-',$string));
0
 

Author Comment

by:brightwood
ID: 18005605
this did the trick, thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
The viewer will learn how to count occurrences of each item in an array.

670 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