本文實例講述了php輸出含有“#”字符串的方法。分享給大家供大家參考,具體如下:
因為#在php中是注釋,無法正常輸出,需要轉換和處理。
輸出頁:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<? function zh( $str ) { for ( $i =0; $i < strlen ( $str ); $i ++) { if ( $str [ $i ]== "#" ) { $str [ $i ]= "@" ; } } return $str ; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=gb2312" /> <title>無標題文檔</title> </head> <body> <a href= "untitled.php?id=<?=zh('c#程序設計')?>" >c#程序設計 </a> </body> </html> |
接受和輸出頁:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<? function zh_2( $str ) { for ( $i =0; $i < strlen ( $str ); $i ++) { if ( $str [ $i ]== "@" ) { $str [ $i ]= "#" ; } } return $str ; } $id = $_GET [ "id" ]; $a =zh_2( $id ); echo $a ; ?> |
希望本文所述對大家PHP程序設計有所幫助。