• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

string parser

How can I replace everything that is not a-z0-9 in a string with "" and " " with "-"

Thank you in advance
0
brightwood
Asked:
brightwood
  • 3
  • 3
1 Solution
 
HuyBDCommented:
$newstring=ereg_replace('\"[a-z0-9]\"', $string,
                  '-');
0
 
brightwoodAuthor Commented:
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
 
brightwoodAuthor Commented:
For example, "test 2.%a" should become "test-2a"
0
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.

 
HuyBDCommented:

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

$newstring=ereg_replace('[^a-zA-Z0-9-]','',ereg_replace(' ','-',$string));
0
 
brightwoodAuthor Commented:
this did the trick, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now