假设以下为我们的字符串数组:$full_name= '["John Doe","David Miller","Adam Smith"]';我们希望输出在一个字符串中:John Doe, David Miller, Adam Smith为此,请使用 json_decode()。示例PHP 代码如下所示 在线演示 输出这将产生以下输出The Result in one string=John Doe, David Miller, Adam Smith
假设以下为我们带有换行的字符串:$sentence = " My name is John Smith My Favorite subject is PHP. ";我们需要删除上述换行符并用空格替换,即输出应为:My name is John Smith My Favourite subject is PHP.为此,请使用 trim() 并在其中使用 preg_replace() 进行替换。示例PHP 代码如下所示 在线演示 输出这将产生以下输出My name is John Smith My Favorite subject is PHP.