Hướng dẫn php get text between tags - php lấy văn bản giữa các thẻ

function contentDisplay[$text]
{
    //replace UTF-8
    $convertUT8 = array["\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"];
    $to = array["'", "'", '"', '"', '-', '--', '...'];
    $text = str_replace[$convertUT8,$to,$text];

    //replace Windows-1252
    $convertWin1252 = array[chr[145], chr[146], chr[147], chr[148], chr[150], chr[151], chr[133]];
    $to = array["'", "'", '"', '"', '-', '--', '...'];
    $text = str_replace[$convertWin1252,$to,$text];

    //replace accents
    $convertAccents = array['À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?'];
    $to = array['A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'];
    $text = str_replace[$convertAccents,$to,$text];

    //Encode the characters
    $text = htmlentities[$text];

    //normalize the line breaks [here because it applies to all text]
    $text = str_replace["\r\n", "\n", $text];
    $text = str_replace["\r", "\n", $text];

    //decode the  tags
    $codeOpen = htmlentities[''];
    if [strpos[$text, $codeOpen]]
    {
        $text = str_replace[$codeOpen, html_entity_decode[htmlentities['']], $text];
    }
    $codeOpen = htmlentities[''];
    if [strpos[$text, $codeOpen]]
    {
        $text = str_replace[$codeOpen, html_entity_decode[htmlentities['']], $text];
    }

    //match everything between  and , the msU is what makes this work here, ADD this to REGEX archive
    $regex = '/[.*]/msU';
    $code = preg_match[$regex, $text, $matches];
    if [$code == 1]
    {
        if [is_array[$matches] && count[$matches] >= 2]
        {
            $newcode = $matches[1];

            $newcode = nl2br[$newcode];
        }

    //remove and this from $text;
    $text = str_replace['' . $matches[1] . '', 'PLACEHOLDERCODE1', $text];

    //convert the line breaks to paragraphs
    $text = '

' . str_replace["\n\n", '

', $text] . '

'; $text = str_replace["\n" , '
', $text]; $text = str_replace['

', '

' . "\n\n" . '

', $text]; $text = str_replace['PLACEHOLDERCODE1', ''.$newcode.'', $text]; } else { $code = false; } if [$code == false] { //convert the line breaks to paragraphs $text = '

' . str_replace["\n\n", '

', $text] . '

'; $text = str_replace["\n" , '
', $text]; $text = str_replace['

', '

' . "\n\n" . '

', $text]; } return $text; }

How to convert a string into an array in PHP

July 5, 2021October 10, 2021 0

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment * document.getElementById["comment"].setAttribute[ "id", "ab155a458f5aa9794b2a673e3d0b9b48" ];document.getElementById["b4ee39581b"].setAttribute[ "id", "comment" ];


Việc sử dụng preg_match trong PHP là gì?

PHP |hàm preg_match [].Hàm này tìm kiếm chuỗi cho mẫu, trả về đúng nếu mẫu tồn tại, nếu không thì trả về sai.Thông thường tìm kiếm bắt đầu từ đầu chuỗi chủ đề.Độ lệch tham số tùy chọn được sử dụng để chỉ định vị trí từ nơi bắt đầu tìm kiếm.searches string for pattern, returns true if pattern exists, otherwise returns false. Usually search starts from beginning of subject string. The optional parameter offset is used to specify the position from where to start the search.

Thẻ dải_ trong PHP là gì?

Chức năng Strip_tags [] là một hàm sẵn có trong PHP được sử dụng để dải một chuỗi từ các thẻ HTML và PHP.Hàm này trả về một chuỗi với tất cả các thẻ null byte, HTML và PHP bị tước từ một $ str.an inbuilt function in PHP which is used to strips a string from HTML, and PHP tags. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str.

Bài Viết Liên Quan

Chủ Đề