close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

str_replace

Thread began 1/31/2013 2:20 am by JamieEff | Last modified 2/06/2013 8:27 am by JamieEff | 1758 views | 6 replies |

JamieEff

str_replace

is there a simpler way of expressing this please?

php:
<a href="newsarticle.php?ID=<?php echo(str_replace(array(" ","!","?",",",".",";",":","'","/"),""$row_NewsRS['NewsTitle'])); ?>">



Do I need to list all the non standard characters (ie ! / , . ' @ etc) individually or is there a way of expressing it without having to list them out?

Also, with this is there a way of making upper case go to lower case?

Cheers

Jamie

Sign in to reply to this post

Jason ByrnesWebAssist

so you want to only allows letters and numbers?
you could use a preg_replace() for that which takes a regular expression

php:
<?php echo(preg_replace("/[^A-Za-z0-9]/"""$row_NewsRS['NewsTitle'])); ?>



See this thread also:
showthread.php?10349055-Remove-non-standard-characters-from-string

you can convert upper case to lower case using strtolower():
function.strtolower.php

Sign in to reply to this post

JamieEff

Thanks Jason

Is there a way to combine that that with replacing a space between words with _

What I have tried (and hasnt worked) is:

<?php echo(str_replace(array(" "),"_", (preg_replace("/[^A-Za-z0-9_]/", "", $row_NewsRS['NewsTitle'])))); ?>
Sign in to reply to this post

Jason ByrnesWebAssist

you include the underscore in the preg_replace() function:
preg_replace("/[^A-Za-z0-9_]/"


dont include the underscore in the pregreplace function, you are replacing it with a blank there so it cannot be found in the result that the replace function is using.

Sign in to reply to this post

JamieEff

but what i am trying to do is take something like this:

the cat sat on the mat!!!!

and make it into

the_cat_sat_on_the_mat

neither way is leaving the underscores in the sentence....

Sign in to reply to this post

Jason ByrnesWebAssist

reverse the order so that your replacing the spaces with underscores directly on the recordset result, then using the preg_replace to strip other characters:

php:
<?php echo(preg_replace("/[^A-Za-z0-9_]/"""str_replace(array(" "),"_", ($row_NewsRS['NewsTitle'])))); ?>
Sign in to reply to this post

JamieEff

thanks Jason

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...