国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial PHP - Html Transfer Code_PHP Tutorial

PHP - Html Transfer Code_PHP Tutorial

Jul 21, 2016 pm 04:09 PM
code html php code Convert


PHP - Html Transfer Code Hypertext conversion code, there is already a lot of it on the market, but I have been practicing it myself in the past few days~~~~

Supports multiple nesting and same-label nesting, mixed highlighting (There is still a little problem)

I feel that it is easy to modify and expand~~~~~~~~~~~

/**************************************************
*? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? *
* Name? ? : Functions 4 Html Transfer Code (HTC)??*
* Version : 1.3.2? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?*
* Author??: Windy_sk? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?*
* Create??: 2003-09-03? ?? ?? ?? ?? ?? ?? ?? ?? ? *
* Modified: 2003-12-17? ?? ?? ?? ?? ?? ?? ?? ?? ? *
* Email? ?: windy_sk@126.com? ?? ?? ?? ?? ?? ?? ? *
* HomePage: None (Maybe Soon)? ?? ?? ?? ?? ?? ?? ?*
* Notice??: U Can Use & Modify it freely,? ?? ?? ?*
*? ?? ?? ???BUT PLEASE HOLD THIS ITEM.? ?? ?? ?? ?*
*? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? *
************************************************** /

$htc_list = array(
"B" "B" => "\1",
"I" "I" => "\1< ;/i>",
"U" "U" => "\1",
"CENTER" => "

\ 1
n" "URL" "URL" lt;a href='mailto:\1 '>\1",
"IMAGE" "IMAGE" => "

n",
"DOWNLOAD" => "exec:get_dl_html('\1')",
"LIST" => "exec:get_list_html(' \1')" , "quote" = & gt; "" & lt; center & gt; & lt; table border = '0' width = '90%' cellspacing = '0' cellpadding = '0' & gt; tr & gt; & lt; td & gt; quote :< ;/tr>
\1
n",
? ? ? ? ? ? ? ? "IFRAME"? ? ? ? => "
n",
? ? ? ? ? ? ? ? "MOVE"? ? ? ? ? ? ? ? => "
\1
n",
? ? ? ? ? ? ? ? "GLOW"? ? ? ? ? ? ? ? => "
\1
n",
? ? ? ? ? ? ? ? "SHADOW"? ? ? ? => "
\1
n",
? ? ? ? ? ? ? ? "DROPSHADOW"? ? ? ? => "
\1
n",
? ? ? ? ? ? ? ? "GBMUSIC"? ? ? ? => "n",
? ? ? ? ? ? ? ? "MUSIC"? ? ? ? ? ? ? ? => "

Download The Music
n",? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? "FLASH"? ? ? ? ? ? ? ? => "
n",
? ? ? ? ? ? ? ? "SHOCKWAVE"? ? ? ? => "
n",
? ? ? ? ? ? ? ? "QUICKTIME"? ? ? ? => "

Download The Movie
n",
? ? ? ? ? ? ? ? "REALPLAYER"? ? ? ? => "

Download The Movie
\n",
? ? ? ? ? ? ? ? "MEDIAPLAYER"? ? ? ? => "

Download The Movie
\n",
? ? ? ? ? ? ? ? "VOTE"? ? ? ? ? ? ? ? => "exec:get_vote_html('\\1')",
? ? ? ? ? ? ? ? );

$htc_list_att = array(
? ? ? ? ? ? ? ? "ALIGN"? ? ? ? ? ? ? ? => "
\\2
n",
? ? ? ? ? ? ? ? "URL"? ? ? ? ? ? ? ? => "\2",
? ? ? ? ? ? ? ? "EMAIL"? ? ? ? ? ? ? ? => "\2",
? ? ? ? ? ? ? ? "IMAGE"? ? ? ? ? ? ? ? => "
\1

n",
? ? ? ? ? ? ? ? "FONTFACE"? ? ? ? => "\2",
? ? ? ? ? ? ? ? "FONTSIZE"? ? ? ? => "\2",
? ? ? ? ? ? ? ? "FONTCOLOR"? ? ? ? => "\2",
? ? ? ? ? ? ? ? "DOWNLOAD"? ? ? ? => "exec:get_dl_html('\1', '\2')",
? ? ? ? ? ? ? ? "LIST"? ? ? ? ? ? ? ? => "exec:get_list_html('\2','\1')",
? ? ? ? ? ? ? ? "ATTACH"? ? ? ? => "exec:get_attach_html('\2', '\1')",
? ? ? ? ? ? ? ? "VOTE"? ? ? ? ? ? ? ? => "exec:get_vote_html('\1','\2')",
? ? ? ? ? ? ? ? );

$htc_list_spl = array(
? ? ? ? ? ? ? ? "PHP"? ? ? ? ? ? ? ? => "exec:get_highlight_html('\1', 'php')",
? ? ? ? ? ? ? ? "CSS"? ? ? ? ? ? ? ? => "exec:get_highlight_html('\1', 'css')",
? ? ? ? ? ? ? ? "HTML"? ? ? ? ? ? ? ? => "exec:get_highlight_html('\1', 'html')",
? ? ? ? ? ? ? ? "SCRIPT"? ? ? ? => "exec:get_highlight_html('\1', 'script')",
? ? ? ? ? ? ? ? "CODE"? ? ? ? ? ? ? ? => "exec:get_code_html('\1')",
? ? ? ? ? ? ? ? "EXECUTE"? ? ? ? => "\1",
? ? ? ? ? ? ? ? );


function get_highlight_html($str, $type = "php") {
? ? ? ? $type = strtolower($type);
? ? ? ? $type_func = $type."_highlight";
? ? ? ? $type = strtoupper($type);
? ? ? ? $result = "
";
? ? ? ? if(!function_exists($type_func)) $type_func = "php_highlight";
? ? ? ? $result .= "
? ? ? ?
? ? ? ?
? ? ? ?
高亮顯示 {$type} 代碼:

? ? ? ?? ?

? ? ? ?? ?".$type_func($str)."
? ? ? ?? ?

? ? ? ? ".($type=="HTML"?"":"")."
? ? ? ?
? ? ? ?
? ? ? ?

? ? ? ? ";
? ? ? ? return $result;
}


function php_highlight($str) {
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? return highlight_string($str, true);
}


function css_highlight($str, $nl = true) {
? ? ? ? $color_1 = "red";
? ? ? ? $color_2 = "green";
? ? ? ? $color_3 = "blue";
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? $str = str_replace("r", "", $str);
? ? ? ? preg_match_all("/[\*.w#: ]+{[^{}]+}/", $str, $arr_css);
? ? ? ? $arr_css = $arr_css[0];
? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? $head = preg_replace("/([\*.w#: ]+{)[^{}]+}/", "\1".($nl?"
n":""), $arr_css[$i]);
? ? ? ? ? ? ? ? $unit = preg_replace("/[\*.w#: ]+{([^{}]+)}/", "\1", $arr_css[$i]);
? ? ? ? ? ? ? ? $unit_list = preg_split("/;s*/", $unit);
? ? ? ? ? ? ? ? $unit = "n";
? ? ? ? ? ? ? ? for($j=0; $j? ? ? ? ? ? ? ? ? ? ? ? if(strlen($unit_list[$j])>0)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $unit .= "? ? " . preg_replace("/s*([w-]+)s*:s*(.*)/e", "'\1 : '.htmlspecialchars('\2').' ; '", $unit_list[$j]) . ($nl?"
n":"n");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? $arr_css[$i] = $head . $unit . "}";
? ? ? ? }
? ? ? ? return join(($nl?"n

n":"nn"), $arr_css);
}


function script_highlight_note($str, $mode = true) {
? ? ? ? $color_note = "gray";
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? $str = preg_replace("/(.*)/isU", "\1", $str);
? ? ? ? $str = $mode?"/*{$str}*/":"http://{$str}";
? ? ? ? return "{$str}";
}


function script_highlight($str, $nl = true) {
? ? ? ? $color_1 = "red";
? ? ? ? $color_2 = "blue";
? ? ? ? $color_3 = "brown";
? ? ? ? $color_4 = "green";
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? $str = htmlspecialchars($str);
? ? ? ? $str = str_replace("=","&equal;",$str);
? ? ? ? $str = str_replace("|","&vertical;",$str);
? ? ? ? $keywords = array(
? ? ? ? ? ? ? ? ? ? ? ? "{$color_1}"? ? ? ? => array("null", "true", "false", "NaN"),
? ? ? ? ? ? ? ? ? ? ? ? "{$color_2}"? ? ? ? => array("var", "for", "if", "else", "switch", "case", "function", "loop", "continue", "break", "<", ">", "!&equal;", "&equal;&equal;", "&equal;", "&&", "&vertical;&vertical;"),
? ? ? ? ? ? ? ? ? ? ? ? "{$color_3}"? ? ? ? => array("window", "self", "this", "event", "document", "opener", "Navigator", "Math", "Array", "String", "Object", "Function", "Number"),
? ? ? ? ? ? ? ? ? ? ? ? );
? ? ? ? foreach($keywords as $key => $value) {
? ? ? ? ? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? ? ? ? ? $str = preg_replace("/(W)(".$value[$i].")(W)/", "\1\2\3", $str);
? ? ? ? ? ? ? ? }
? ? ? ? }
? ? ? ? $str = preg_replace("/(.|s)([a-z]+)(/i" ,"\1\2(", $str);
? ? ? ? $str = preg_replace("/.(w+)(?!()/i" ,".\1", $str);
? ? ? ? $str = preg_replace("http:///([^n]*)n/e" ,"script_highlight_note('\1', false)", $str);
? ? ? ? $str = preg_replace("http://*(.*?)*//es" ,"script_highlight_note('\1')", $str);? ? ? ?
? ? ? ? $str = str_replace("t", "? ? ", $str);
? ? ? ? $str = str_replace("&equal;","=",$str);
? ? ? ? $str = str_replace("&vertical;","|",$str);
? ? ? ? return $nl?nl2br($str):$str;
}


function html_highlight_attr($att) {
? ? ? ? $color_1 = "red";
? ? ? ? $color_2 = "brown";
? ? ? ? $color_3 = "black";
? ? ? ? $att = str_replace("\"",""",$att);
? ? ? ? $att = preg_replace("/=s*('|")([^'"]+)\1/eU","'=\1'.preg_replace('/s+/','|:s:|','\2').'\1'",$att);
? ? ? ? $att = str_replace("\"",""",$att);
? ? ? ? $att .= " ";
? ? ? ? preg_match_all("/[a-z:/-]+(=(['"]?).*[^\\]{1}\2?)?s+/iU", $att, $att_list);
? ? ? ? $att_list = $att_list[0];
? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? if(empty($att_list[$i])) continue;
? ? ? ? ? ? ? ? $att_list[$i] = trim($att_list[$i]);
? ? ? ? ? ? ? ? $att_list[$i] = preg_replace("/([^=]+)([=]?)(['"]?)(.*)(\3)/", "\1\2\3\4\3", $att_list[$i]);
? ? ? ? }
? ? ? ? return str_replace("|:s:|", " ", join(" ", $att_list));
}


function html_highlight($str) {
? ? ? ? $color_1 = "red";
? ? ? ? $color_2 = "blue";
? ? ? ? $color_3 = "gray";
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? preg_match_all("//isU", $str, $arr_tmp);
? ? ? ? $arr_script = $arr_tmp[0];
? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? $str = str_replace($arr_script[$i], "
::script_{$i}::
", $str);
? ? ? ? ? ? ? ? $arr_script[$i] = preg_replace("//iseU", "''", $arr_script[$i]);
? ? ? ? }
? ? ? ? $str = preg_replace("/(]*>)(.*)()/ieU" ,"'\1'.htmlspecialchars('\2').'\3'", $str);
? ? ? ? $str = preg_replace("//seU" ,"''", $str);
? ? ? ? $str = preg_replace("/]*)>(.*)/isU" ,"\2", $str);
? ? ? ? $str = preg_replace("/<([a-z:]+)s*(.*?)( /|/)?>/ise" ,"'<\1 '.html_highlight_attr('\2').'\3>'", $str);
? ? ? ? $str = preg_replace("/<(/[a-z:]+)>/i" ,"<\1>", $str);
? ? ? ? $str = preg_replace("/<(!--.*--)>/sU" ,"<\1>", $str);
? ? ? ? $str = preg_replace("/]*)>(.*)/iseU" ,"''", $str);
? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? $str = str_replace("
::script_{$i}::
", $arr_script[$i], $str);
? ? ? ? }
? ? ? ? $str = str_replace("", "
", $str);
? ? ? ? $str = str_replace("", "", $str);
? ? ? ? $str = str_replace(" >", ">", $str);
? ? ? ? $str = str_replace("??"," ?",$str);
? ? ? ? $str = str_replace("t"," ? ?",$str);
? ? ? ? return nl2br($str);
}


function get_file_pic($filename) {
? ? ? ? global $root_path;
? ? ? ? $ext = str_replace(".","",strrchr($filename,"."));
? ? ? ? $pic = $root_path."images/mime_type/{$ext}.gif";
? ? ? ? return file_exists($pic)?"$pic":$root_path."images/mime_type/attch.gif";
}


function get_dl_html($filename, $str = "") {
? ? ? ? return " ".(empty($str)?basename($filename):$str)."";
}


function get_attach_html($filename, $id) {
? ? ? ? return " $filename";
}


function get_vote_html($vote_idx, $message = ""){
? ? ? ? global $db_host, $db_user, $db_pass, $db_name;
? ? ? ? $db = new DB_Manager($db_host, $db_user, $db_pass);
? ? ? ? $db->Connect();
? ? ? ? $db->SelectDB($db_name);
? ? ? ? $db->Query("select * from mnms_poll where id=".$vote_idx);
? ? ? ? $record = $db->GetRS();
? ? ? ? $str = "";
? ? ? ? $db->close();
? ? ? ? unset($db);
? ? ? ? if($record) {
? ? ? ? ? ? ? ? $username = "dummy";
? ? ? ? ? ? ? ? $if_vote = !(strpos($record[vote_user], "|{$username}|")===false)
strpos($record[vote_user], "|".GetIp()."|");
? ? ? ? ? ? ? ? $str .= "
? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?? ?".(empty($message)?$record[vote_title]:$message)."
? ? ? ? ? ? ? ? ? ? ? ?? ?

? ? ? ? ? ? ? ? ? ? ? ?? ?";
? ? ? ? ? ? ? ? $vote_list = split("::",$record[vote_list]);
? ? ? ? ? ? ? ? $vote_count = split("::",$record[vote_count]);
? ? ? ? ? ? ? ? $vote_users = count(split("n", $record[vote_user])) - 1;
? ? ? ? ? ? ? ? $vote_sum = array_sum($vote_count);
? ? ? ? ? ? ? ? $str .= "
? ? ? ? ? ? ? ? ? ? ? ?? ???";
? ? ? ? ? ? ? ? if($vote_sum==0) $vote_sum = 1;
? ? ? ? ? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? ? ? ? ? $str .= "
? ? ? ? ? ? ? ? ? ? ? ?? ???
n";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? $str .= "";
? ? ? ? ? ? ? ? $str .= "
? ? ? ? ? ? ? ? ? ? ? ?? ?
目前共有 {$vote_users} 人參與了本投票
".($if_vote?"? ":"").htmlspecialchars($vote_list[$i])." 占總票數(shù)的 ".ceil((int)$vote_count[$i]*100/$vote_sum)."%

".($if_vote?"您已經(jīng)投過(guò)票了!":"? ?")."

? ? ? ? ? ? ? ? ? ? ? ?? ?

? ? ? ? ? ? ? ? ? ? ? ?
";
? ? ? ? }
? ? ? ? return $str;
}


function get_code_html($str) {
? ? ? ? $str = str_replace("\"",""",$str);
? ? ? ? return "
? ? ? ?
? ? ? ?? ?
? ? ? ?


? ? ? ?? ???
? ? ? ?? ???
? ? ? ?? ???
? ? ? ?? ???(提示:可以先修改部分代碼)
? ? ? ?? ?
";
}


function get_list_html($content, $type = "") {
? ? ? ? $content = preg_replace("/(
)?[rn]+/", "n", $content);
? ? ? ? $content = preg_replace("/[rn]+/", "n", $content);
? ? ? ? $content = preg_replace("/^[n]*(.*)[n]*$/m", "\1", $content);
? ? ? ? $content = str_replace("n", "
  • ", $content);
    ? ? ? ? $content = "
    • $content
    n";
    ? ? ? ? return $content;
    }


    function html_trans($str) {
    ? ? ? ? $search??= array("&",? ? ? ? ? ? ? ? "'",? ? ? ? ? ? ? ? """,? ? ? ? ? ? ? ? "<",? ? ? ? ">",? ? ? ? "??",? ? ? ? ? ? ? ? "t");
    ? ? ? ? $replace = array("&",? ? ? ? "'",? ? ? ? """,? ? ? ? "<",? ? ? ? ">",? ? ? ? "? ",? ? ? ? "? ? ");
    ? ? ? ? return nl2br(str_replace($search, $replace, $str));
    }


    function link_url($str) {
    ? ? ? ? $str = preg_replace("/((http|ftp|mms|rtsp|pnm|mailto)://[w@:./?=&;#-%]+)/i", "\1", $str);
    ? ? ? ? $str = preg_replace("/(w+@(w+.)+[w]{2,3})/i", "\1", $str);
    ? ? ? ? $str = preg_replace("/(href|src)='[^<]+'/iU", "\1=\2", $str);
    ? ? ? ? return $str;
    }


    function htc2html_loop($str) {
    ? ? ? ? global $htc_list, $htc_list_att;
    ? ? ? ? foreach($htc_list as $key => $value) {
    ? ? ? ? ? ? ? ? if(substr($value,0,5)=="exec:"){
    ? ? ? ? ? ? ? ? ? ? ? ? $str = preg_replace("/[$key]((.(?![$key(s?=s?([^]]+))?]))*)[/$key]/iexsU", substr($value,5), $str);
    ? ? ? ? ? ? ? ? }else {
    ? ? ? ? ? ? ? ? ? ? ? ? $str = preg_replace("/[$key]((.(?![$key(s?=s?([^]]+))?]))*?)[/$key]/ixsU", "$value", $str);
    ? ? ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? ? ? foreach($htc_list_att as $key => $value) {
    ? ? ? ? ? ? ? ? if(substr($value,0,5)=="exec:"){
    ? ? ? ? ? ? ? ? ? ? ? ? $str = preg_replace("/[$keys?=s?([^]]+)]((.(?![$key(s?=s?([^]]+))?]))*)[/$key]/iesxU", substr($value,5), $str);
    ? ? ? ? ? ? ? ? } else {
    ? ? ? ? ? ? ? ? ? ? ? ? $str = preg_replace("/[$keys?=s?([^]]+)]((.(?![$key(s?=s?([^]]+))?]))*)[/$key]/isxU", "$value", $str);
    ? ? ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? ? ? return $str;
    }


    function htc2html($str, $trans_url = true , $loop = 3) {
    ? ? ? ? global $htc_list_spl;
    ? ? ? ? $str = preg_replace("/([w+])s*/ixs","\1",$str);
    ? ? ? ? $str = preg_replace("/s*([/w+])/ixs","\1",$str);
    ? ? ? ? foreach($htc_list_spl as $key => $value) {
    ? ? ? ? ? ? ? ? preg_match_all("/[$key](.*)[/$key]/ixsU", $str, $arr_tmp);
    ? ? ? ? ? ? ? ? $arr_spl[$key] = $arr_tmp[0];
    ? ? ? ? ? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? ? ? ? ? $str = str_replace($arr_spl[$key][$i], "
    ::{$key}_{$i}::
    ", $str);
    ? ? ? ? ? ? ? ? ? ? ? ? if(substr($value,0,5)=="exec:"){
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $arr_spl[$key][$i] = preg_replace("/[$key](.*)[/$key]/iexsU", substr($value,5), $arr_spl[$key][$i]);
    ? ? ? ? ? ? ? ? ? ? ? ? } else {
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $arr_spl[$key][$i] = preg_replace("/[$key](.*)[/$key]/ixsU", "$value", $arr_spl[$key][$i]);
    ? ? ? ? ? ? ? ? ? ? ? ? }
    ? ? ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? ? ? $str = html_trans($str);
    ? ? ? ? while($loop-- > 0) {
    ? ? ? ? ? ? ? ? if(!preg_match("/[(w+)(s?=s?([^]]+))?](.*)[/\1]/isU", $str)) break;
    ? ? ? ? ? ? ? ? $str = htc2html_loop($str);
    ? ? ? ? }
    ? ? ? ? if($trans_url) $str = link_url($str);
    ? ? ? ? foreach($htc_list_spl as $key => $value) {
    ? ? ? ? ? ? ? ? for($i=0; $i? ? ? ? ? ? ? ? ? ? ? ? $str = str_replace("
    ::{$key}_{$i}::
    ", $arr_spl[$key][$i], $str);
    ? ? ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? ? ? return $str;
    }
    ?>



    使用方法:

    echo htc2html($str);

    OK 了~~~~~~~~

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/314366.htmlTechArticlePHP - Html Transfer Code超文本轉(zhuǎn)換碼,市面上這東西已經(jīng)很濫(多)了,不過(guò)是這幾天自己實(shí)踐了一下~~~~ 支持 多重嵌套 和 同標(biāo)簽嵌套,混合...
  • Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

    The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

    PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

    To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

    How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

    UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

    How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

    In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

    JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

    JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

    Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

    std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

    How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

    In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

    How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

    ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

    See all articles