Home  >  Article  >  Backend Development  >  PHP small function to replace html content

PHP small function to replace html content

WBOY
WBOYOriginal
2016-07-25 08:55:33969browse
  1. /**

  2. * Replace html content
  3. * by bbs.it-home.org
  4. */
  5. function htmlsp($a)
  6. {
  7. if(strpos($a, '<', 0)=== false)
  8. {
  9. echo $a;
  10. }else
  11. {
  12. while(strpos($a, '<', 0)>=0)
  13. {
  14. if(strpos($a, '<', 0 )===false)
  15. break;

  16. $x1 = strpos($a, '<', 0);

  17. $x2 = strpos($a, '>', 0 ; $t = substr($a, $x1, $x2 - $x1 + 1);

  18. $a = str_replace($t,'',$a);

  19. }
  20. echo $ a;
  21. }
  22. }

  23. Copy code
>>>Articles you may be interested in: PHP string replacement function can replace multiple keywords at the same time

Example code for php to replace individual words in the file PHP keyword replacement class (avoid repeated replacement, retain and restore the original link) php code to implement keyword replacement and highlighting Example code of php keyword replacement class Sharing function for php content keyword replacement Code sharing for php to find and replace http addresses in strings Example code of php batch replacing relative addresses with absolute addresses php code to replace parameter variables in the URL php code to replace special characters in extra long text Provide several php methods to replace newline characters Use regular expressions for find and replace

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