Welcome Guest, Not a member yet? Register   Sign In
Stripping illegal URL characters from strings
#1

[eluser]Shodan[/eluser]
Hi all,

I'm working on a site that will be using product names in site's page URLs.

I'm redesigning the site so the data already exists. Unfortunately, there's lots of '/'s and '&'s in existing product names so I need to scan through the database and remove any illegal characters from the product (and category) names.

Is there a simple way to scan a string for illegal characters and remove them (or at worst, replace with white space)? I'd also like to replace all the ampersands with the word: "and".

I know this is a job for Regex but to be honest, it baffles me and I can't seem to find a decent, straightforward tutorial.

Thanks in advance for any help!

Regards,
Terry
#2

[eluser]worchyld[/eluser]
str_replace() maybe?
#3

[eluser]alpar[/eluser]
You could really straight out that data in the database using mysql (but make a backup first!!!).
Here is a solution without regexps

here is the mysql function that you need.

of course for this you need to know all the special chars that might occur.
#4

[eluser]Shodan[/eluser]
Thanks for the replies, guys.

I've just read the manual entry for str_replace and noticed that you can give it an array of strings to replace if found.. never realised that!

You learn something new every day!

I'll report back if it works.

Cheers!
#5

[eluser]esra[/eluser]
If you have access to a copy of Microsoft Access, you can access other databases using ODBC. There are a number of ODBC drivers floating about on the web for MySQL. Some work better than others.

Access features a search by column option, so you could load a table, then perform a search on your product name and description columns independently. Searches could be performed to find every instance of a string and you can choose to correct the problem or not correct it. You can also stop a search and replace operation at any time if you need to perform manual changes. You can also perform a 'replace all' where appropriate.

I've been using it correct character encoding problems when converting data to UTF-8. The above works very well for my needs.




Theme © iAndrew 2016 - Forum software by © MyBB