Home  >  Article  >  Backend Development  >  How to output string containing "#" in php

How to output string containing "#" in php

高洛峰
高洛峰Original
2017-01-21 13:47:491640browse

The example in this article describes the method of php outputting a string containing "#". Share it with everyone for your reference, the details are as follows:

Because # is a comment in php, it cannot be output normally and needs to be converted and processed.

Output page:

<?
 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(&#39;c#程序设计&#39;)?>">c#程序设计
</a>
</body>
</html>

Accepting and output page:

<?
 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;
?>

I hope this article will be useful to everyone in PHP programming. helped.

For more articles related to methods of php outputting strings containing "#", please pay attention to the PHP Chinese website!

Statement:
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