我正在检索一个包含来自另一个页面的£符号的变量.我想删除它,我尝试使用str_replace但我留下以下内容:
100.
$amount = str_replace('£', '', $amount);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要在标签中单独替换几个单词.例如
文本文本文本狗文本猫文本文本鼠标.
需要被替换<b>dog</b>或者<b>cat</b>或者<b>mouse</b>如果匹配.我需要更换一次.如果它发现单词dog意味着替换唯一的狗<b>dog</ b>.仅此而已.即使猫或老鼠是文本.
我有代码.
var str = "dog text cat text mouse",
reg = /dog|cat|mouse/;
str = str.replace(reg, '<b>dog</b>').
Run Code Online (Sandbox Code Playgroud)
对不起,这只能替换任何匹配的<b>dog</b>.请帮帮我.
我试图简单地阅读,从而重现以下代码.
INSERT INTO `actions` (`aid`, `type`, `callback`, `parameters`, `description`) VALUES
('5', 'system', 'views_bulk_operations_script_action', 'a:1:{s:6:"script";s:452:"$string = $object->field_ruling_content[0][''value''];\r\n// do replacements\r\n$search = array(\r\n ''<h4>Membres</h4>'', \r\n ''<h4>Membre</h4>'',\r\n ''<h2><strong>Membres</strong></h2>'',\r\n ''<h2><strong>Membre</strong></h2>'',\r\n);\r\n$replace = array(\r\n ''<h2>Membres</h2>'',\r\n ''<h2>Membre</h2>'',\r\n ''<h2>Membres</h2>'',\r\n ''<h2>Membre</h2>'',\r\n );\r\n$string = str_replace($search, $replace, $string);\r\n$object->field_ruling_content[0][''value''] = $string;\r\nnode_save($object);";}', 'Cleanup');
Run Code Online (Sandbox Code Playgroud)
让我困惑的唯一一点就是这个a:1:{s:6:"script";s:452:".我试图查找a:1:,s:6:并s:452:在谷歌,但它并没有完全得到我,我一直在寻找的结果.它们是什么,它们是什么意思?
我有一个可以假设两种形式的String
第一种形式
file:///mnt/sdcard/myfolder/myfile.txt
Run Code Online (Sandbox Code Playgroud)
第二种形式
/file://mnt/sdcard/myfolder/myfile.txt
Run Code Online (Sandbox Code Playgroud)
而且我总是需要表格中的字符串
/mnt/sdcard/myfolder/myfile.txt
Run Code Online (Sandbox Code Playgroud)
所以我使用了replace命令
myPath=path.replace("file://", "");
myPath= path.replace("/file:/", "");
Run Code Online (Sandbox Code Playgroud)
但不幸的是不起作用
和字符串myPath结果
file:///mnt/sdcard/myfolder/myfile.txt
Run Code Online (Sandbox Code Playgroud)
怎么了?
下面的代码在WordPress内容中搜索单词,并用链接和div替换这些单词.它会产生一个问题,即div关闭<p>它插入的标签.
$myposts = get_pages(args...);
$replace = array();
$i = 1;
foreach( $myposts as $post ) {
setup_postdata($post);
$replace[get_the_title()] = '<a href="#popupBasic' . $i . '" data-rel="popup">' . get_the_title() . '</a><div data-role="popup" class="tooltipBox" id="popupBasic' . $i . '">' . get_the_content() . '</div>';
$i++;
}
$text = str_replace(array_keys($replace), $replace, $text);
Run Code Online (Sandbox Code Playgroud)
为什么str_replace会<p>像这样打破标签?
<div>
<p>Some random text thats been <a href="#" class="link">cutt</a></p><div style="display: none;"><!-- placeholder --></div> off.<p></p>
</div>
Run Code Online (Sandbox Code Playgroud)
如果它无法在PHP中修复,我们可以用jQuery解决这个问题吗?我想把那些被切断的词放回去,在这种情况下"关闭".进入<p>链接后关闭的标记.并最后删除空<p>标签.
我有以下功能和使用str_replace给出了意想不到的结果
function repo($text) {
$search = array("0","1","2","3","4","5","6","7","8","9");
$replace = array("z30","z31","z32","z33","z34","z35","z36","z37","z38","z99");
$text = str_replace($search,$replace,$text);
return $text;
}
echo repo('0');
Run Code Online (Sandbox Code Playgroud)
预期的答案是
z30
Run Code Online (Sandbox Code Playgroud)
而我得到了
zz330
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如何在这样的PHP字符串中替换"/"?
C:\files\mybundle/files/example.pdf
Run Code Online (Sandbox Code Playgroud)
我想要的输出:
C:\files\mybundle\files\example.pdf
Run Code Online (Sandbox Code Playgroud)
这不起作用:
$urlFormatted = str_replace('/', '\', $string)
Run Code Online (Sandbox Code Playgroud) 我有一些文本,我需要删除前面的代码,我使用这样的很多变种:
$answer = str_replace('<td style="background-color:#80F9CC;">', '', $answer);
$answer = str_replace('<td style="background-color:#E1E3E4;">', '', $answer);
$answer = str_replace('<td style="background-color:#D1D3D4;">', '', $answer);
$answer = str_replace('<td style="background-color:#73F6AB;">', '', $answer);
$answer = str_replace('<td style="background-color:#3CEB88;">', '', $answer);
Run Code Online (Sandbox Code Playgroud)
有没有办法创建一个str_replace函数,将通过一些掩码删除此文本?
我试图替换字符串中的单词但是我想在函数中找到单词并将其替换为带有确切长度的星号的单词?
这是可能的还是我需要以其他方式做到这一点?
$text = "Hello world, its 2018";
$words = ['world', 'its'];
echo str_replace($words, str_repeat("*", count(FOUND) ), $text);
Run Code Online (Sandbox Code Playgroud) 不知道为什么这行不通,因为我显然可以这样删除其他符号,但这是:str = str.replace('¥', '');无法删除有问题的符号¥。任何想法如何删除这个东西?
我也尝试过这个str = str.replace(/¥/g, '');,但是str = str.replace(/\¥/g, '');没有用。
显然,我可以通过敲敲字符串中的第一个字符来删除它,但是我认为必须有一种方法可以真正检测到该东西,以防万一它不在最前面并且我需要将其删除。