Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Replace a Group of Characters by Another Group
How To Replace a Group of Characters by Another Group? - PHP Script Tips - PHP Built-in Functions for Strings
✍: FYIcenter.com
While processing a string, you may want to replace a group of special characters with some other characters. For example, if you don't want to show user's email addresses in the original format to stop email spammer collecting real email addresses, you can replace the "@" and "." with something else. PHP offers the strtr() function with two format to help you:
Here is a PHP script on how to use strtr():
<?php
$email = "joe@dev.fyicenter.moc";
$map = array("@" => " at ", "." => " dot ");
print("Original: $email\n");
print("Character replacement: ".strtr($email, "@.", "#_")."\n");
print("Substring replacement: ".strtr($email, $map)."\n");
?>
This script will print:
Original: joe@dev.fyicenter.moc Character replacement: joe#dev_fyicenter_moc Substring replacement: joe at dev dot fyicenter dot moc
To help you to remember the function name, strtr(), "tr" stands for "translation".
2007-04-20, 5259👍, 0💬
Popular Posts:
How do we configure “WebGarden”? “Web garden” can be configured by using process model settings in...
How To Manage Transaction Isolation Level? - Oracle DBA FAQ - Introduction to PL/SQL Transaction iso...
What will be printed as the result of the operation below: main() { int x=20,y=35; x=y++ + x++; y= +...
What is the difference between const char* p and char const* p? In const char* p, the character poin...
How To Enter a New Row into a Table Interactively? - Oracle DBA FAQ - Introduction to Oracle SQL Dev...