Solved

string parser

Posted on 2006-11-23
6
240 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 17

Expert Comment

by:HuyBD
ID: 18005526

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

Accepted Solution

by:
HuyBD earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

828 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