替换没有功能的文本 [英] replace text without function

查看:55
本文介绍了替换没有功能的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 php 问题.我有一个 php 代码,它打印一些长文本.我想用N"替换输出文本中的n"字符.我可以创建一个函数.但我不能(也不喜欢!)将我的文本放到一个函数中(因为我有很多文本!).有没有什么方法可以不用任何功能用N"代替n"???

I've a php question. I've a php code, it prints some long texts. I want replace "n" character in output text with "N". I can create a function. but I can't (and don't like!) put my text to a function (because I have many texts!). Is there any way to replace "n" with "N" without any function???

谢谢..

推荐答案

无需创建一个函数,只需使用str_replace,为此目的的内置函数如下:

No need to create a function, just use str_replace, the built in function for this purpose like this:

$output_text = str_replace('n', 'N', $input_text);
echo $output_text;

<小时>

如果你不想把你的文本放在一个函数中,因为有很多文本(如你所说),这样做:


If you don't want to put your text in a function, because there is lots of text (as you say), do it like this:

<?php
 ob_start();

 //..... ALL YOUR CODE GOES HERE

 $FullOutput = ob_get_clean();
 echo str_replace('n', 'N', $FullOutput);
?>

这有效地缓冲(捕获和存储)您的所有输出,最后得到它并将n"替换为N"并回显它.

This effectively buffers (catches and stores) all your output and at the end get's it and replaces the 'n' to 'N' and echoes it.

这篇关于替换没有功能的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆