Softpedia
 


SCRIPTS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Peardrop CMS 0.2.3
  • CommaFeed 0.0.1
  • Squash
  • Pick-a-Color 1.1.5
  • MVIS Security Center 1....
  • EasyZoom 1.0.3
  • jQueryGantt
  • IMDBPHP 2.1.8
  • Dynamic WordPress Form ...
  • PathFinding.js 0.4.1
  • Home > Scripts > Snippets

    Censoring messages in PHP

    download button


    Downloads: 472  Tell us about an update
    User Rating:
    Rated by:
    Fair (2.6/5)
    16 user(s)
    Developer:

    Website:

    License / Price:

    Platforms:

    Databases:

    Language:

    Last Updated:

    Category:
    saifullah shafiq | More scripts
    px.sklar.com
    Freeware 

    Windows / Linux / BSD / Solaris
    N/A
    PHP
    June 25th, 2007, 10:29 GMT
    C: \ Snippets

     Read user reviews (0)  Refer to a friend  Subscribe

    Censoring messages in PHP description

    Censoring messages in PHP shows how to hide email addresses in your messages.

    Consider that you place a messaging system on your site from where users of your site can communicate wit site froher. This would really increase hits on your site but what if users give each other their email address in the message then they wont need your messaging system, hence they wont be coming to your site. So you need to censor out any email address in the messages that users send to each other.

    I came up with an efficient yet simple solution to this problem. All you have to do is to search for any '@' in the message and then censor out few characters that appear after it and before it. For example, if you type "myemailaddress@hotmail.com" then the script will display it like my*********com.

    Here is the how it works

    For Example we got the following message:

    $message = "hello this is my email address: myaddress@mydomain.com"

    1. First you search for '@' in the message that is passed to the function. strrpos returns the position of the character you specify.

    $emailpos = strrpos($message,'@');
    This line will return the value '42'.

    2. Then we check if there was a '@' in the message if none then we simply return the passed message other wise we proceed to the next step.

    3. Then we take out the sub string (email address) based on the position we got from above. For Example, if we got the following message.

    $email = substr($message,$emailpos-5,12 );
    Here we start the sub string by first going back 5 characters and then taking out next 12 characters. This will return 'dress@mydoma' you can change the length by changing values in the above function. I only used 12 characters because i think that is sufficient. You can change this according to your needs.

    4. Then in the final step we simplly need to replace this substring (email address) with anything we like. Iprefer using '******'. You can use whatever you want.

    $message =eregi_replace($email,"********",$message);

    5. Thats it! Now you just return the censored $message.



    TAGS:

    Censoring messages | php messages | php censoring | php | Censoring | messages

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM