假设以下为我们的字符串数组:$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.