The regular expression of PHP

Source: Internet
Author: User
Tags chr

Recently in the writing BBS, encountered code conversion problems. Looking for a long time, only to get a better solution, can completely restore the original text.
Here is a post for you to correct me.
System: linux+php4+oracle8i

?
--title, name and other fields of storage processing (go to the end of space)
function Trans_string_trim ($STR) {
$str =trim ($STR);
$str =eregi_replace ("" "," "" ", $str);
$str =stripslashes ($STR);
return $str;
}

--The article warehousing processing, namely textarea field;
function trans_string ($STR) {
$str =eregi_replace ("" "," "" ", $str);
$str =stripslashes ($STR);
return $str;
}

--displayed in the form from the library, in text with trans, in textarea, no conversion, direct display

--Display on a Web page, filter HTML code, include a link address
function trans ($string) {
$string =htmlspecialchars ($string);
$string =ereg_replace (CHR), "<br>", $string);
$string =ereg_replace (CHR), "", $string);
return $string;
}

--Display on Web page, do not filter HTML code;
function Trans_web ($string) {
$string =ereg_replace (CHR), "<br>", $string);
$string =ereg_replace (CHR), "", $string);
return $string;
}

--Display on Web page, filter HTML code and trailing space, mainly used to display user nickname
function Trans_trim ($string) {
$string =trim ($string);
$string =htmlspecialchars ($string);
$string =ereg_replace (CHR), "<br>", $string);
$string =ereg_replace (CHR), "", $string);
return $string;
}

--shown in span;
function Trans_span ($string) {
$string =ereg_replace (CHR), "/n", $string);
$string =ereg_replace (CHR), "", $string);
$string =ereg_replace ("" "," "", $string);
return $string;
}

--Display cookies on the Web, filter HTML
function Trans_cookie ($STR) {
$str =trans ($STR);
$str =stripslashes ($STR);
$str =eregi_replace ("" "," "", $str);
return $str;
}
?>
---------------------------
Finally, incidentally, if you show a paragraph in a span and use substr to set a long string, remember to add a space behind the parameters of the span, or you'll mess up the HTML code when you intercept half of the characters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.