$bodytag=str_replace("%body%","black","<body text='%body%'>");echo$bodytag;//<body text='black'>$vowels=array("a","e","i","o","u","A","E","I","O","U");$onlyconsonants=str_replace($vowels,"","Hello World of PHP");echo$onlyconsonants;//Hll Wrld f PHP$phrase="You should eat fruits, vegetables, and fiber every day.";$healthy=array("fruits","vegetables","fiber");$yummy=array("pizza","beer","ice cream");$newphrase=str_replace($healthy,$yummy,$phrase);echo$newphrase;//You should eat pizza, beer, and ice cream every day.$str=str_replace("ll","","good golly miss molly!",$count);echo$count;//2$str="Line 1\nLine 2\rLine 3\r\nLine 4\n";$order=array("\r\n","\n","\r");$replace='<br />';$newstr=str_replace($order,$replace,$str);echo$newstr;//Line 1<br />Line 2<br />Line 3<br />Line 4<br />// 输出 F ,因为 A 被 B 替换,B 又被 C 替换,以此类推...// 由于从左到右依次替换,最终 E 被 F 替换$search=array('A','B','C','D','E');$replace=array('B','C','D','E','F');$subject='A';echostr_replace($search,$replace,$subject);//F$letters=array('a','p');$fruit=array('apple','pear');$text='a p';$output=str_replace($letters,$fruit,$text);echo$output;//apearpearle pear
<?php$array=['lastname','email','phone'];var_dump(implode(",",$array));// string(20) "lastname,email,phone"// Empty string when using an empty array:var_dump(implode('hello',[]));// string(0) ""// The separator is optional:var_dump(implode(['a','b','c']));// string(3) "abc"?>
1 什么是内容协商
简单说就是服务提供方根据客户端所支持的格式来返回对应的报文,在 Spring 中,REST API 基本上都是以 json 格式进行返回,而如果需要一个接口即支持 json,又支持其他格式,开发和维护多套代码显然是不合理的,而 Spring 又恰好提供了该功能,那便是Conten…