PHP page Tag tag replacement unit test code

Source: Internet
Author: User
Tags tagname rekey
<?phpclass tagreplaceapi{public function Tagreplace ($content, $tags) {//replace content and all Tags$replacearr = Array (); $ Tagslength=count ($tags); for ($i =0; $i < $tagslength; $i + +) {$content = $this, Tagreplacecontent ($content, $tags [$ I], $REPLACEARR, $i);} foreach ($replaceArr as $key = + $value) {//echo "key=". $key. ", value=." $value. "<br/>"; $content = Str_replace ($key, $value, $content);} return $content;} Public Function Tagreplacecontent ($content, $tag, & $replaceArr, $i) {//replace content and tag$tagname = $tag [' TagName ']; $tagUrl = $tag [' Tagurl '];//echo "tagname=". $tagName. ", Tagurl=." $tagUrl. "<br/>", $reValue = "<a href=\" ". $tagUrl." \ ">". $tagName. " </a> "; $content = Str_replace ($reValue, $tagName, $content); $reKey =" ###### ". $i. "######"; $content = Str_replace ($tagName, $reKey, $content); $REPLACEARR [$reKey] = $reValue; return $content;}} $content = ' generally do not pay attention to millet feel normal but the millet genuine black bracelet a piece of millet genuine piston headset 2-generation coffee gold photos, but carefully observe millet genuine black bracelet will find the most is a genuine piston headset 3 generations black only passing birds, Was captured very clearly, without the slightest blur, to know that the mobile cameraThe actual imaging effect of the state object is generally not the same as millet genuine piston headset 2 generations of coffee gold, not to mention is a flying Big bird, the picture does not appear jitter, very clear, it is obvious that Millet 5 in the movement of the shooting should be very millet to force. '; $tags = Array (' tagName ' + ' genuine piston headset 2 generation coffee gold ', ' tagurl ' = ' http://www.mi.com/kfj/'), Array (' tagName ' = ' genuine piston headphones 3 generation black ', ' tagurl ' = ' http://www.mi.com/hei/'), Array (' tagName ' = ' millet ', ' tagurl ' = ' http://www.mi.com ') /'); $tagReplaceApi = new Tagreplaceapi (); $content = $tagReplaceApi, Tagreplace ($content, $tags); Echo $content; echo "<br/>", echo "<br/>"; $content = $tagReplaceApi-Tagreplace ($content, $tags); echo $content; echo "& Lt;br/> "; echo" <br/> "; $content = Tagreplace ($content, $tags), $tagReplaceApi, Echo $content; >
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.