我想替换一个字符串,如:
<input type="hidden" name="id" value="12345" />
Run Code Online (Sandbox Code Playgroud)
但我遇到的问题是值值(12345)每次都不同,所以我该怎样做我想做的事情?..我猜的是正则表达式,但还没有任何线索
在 PHP 中是否有preg_match不需要使用正则表达式的等价物?还有str_replace()的preg_replace。有什么东西可以preg_match。
*更新 *我只想用另一个替换已知字符串。使用正则表达式似乎有点矫枉过正。
我有字符串“这是[test1],而不是[test2]”,我想将它们与“[test1]”和“[test2]”匹配。
我有函数str_replace()的问题.我有这个代码:
$headImageName = "C:\Program Files\EasyPHP-5.3.3.1\www\realitka/headImages/hImageMini4e7b5a6ea8c95Pyro.png";
die(var_dump(str_replace("C:\Program Files\EasyPHP-5.3.3.1\www\realitka/", "", $headImageName)));
Run Code Online (Sandbox Code Playgroud)
var_dump的结果又是:
string(88) "C:\Program Files\EasyPHP-5.3.3.1\www\realitka/headImages/hImageMini4e7b5bae39148Pyro.png"
Run Code Online (Sandbox Code Playgroud)
你知道问题出在哪里吗?
我试图在以下代码中替换CSS样式:
var theHTML = this.html();
theHTML.replace("style=\"display:none;\"", "style=\"display:inline;\"");
alert(theHTML);
Run Code Online (Sandbox Code Playgroud)
html看起来像这样:
<IMG SRC="picturesFromServer.asp?PhotoId=365481" style="display:none;">
Run Code Online (Sandbox Code Playgroud)
然而,一旦我检查它是否改变它,它继续显示无,而不是内联.我只是想在打印之前让它可见.
我究竟做错了什么?
$title = get_the_title();
$firstLetter = $title[0];
$title[0] = '<span class = "wrapBlue">' . $firstLetter . '</span>';
echo $title; // comes out with weird switched around string?
Run Code Online (Sandbox Code Playgroud)
get_the_title() 是一个wordpress功能.
var_dump on $title 给出一个长度为21的字符串.
var_dump on $firstLetter 给出一个包含长度为1的正确字符的字符串
我必须在此示例文本中更改两件事:
example_1,example_2
我需要这样出现:
example 1, example 2
所以我需要用空格""替换"_"以及用空格替换","到",".目前我在下面有这个代码,它取代了下划线,但我不知道如何在这段代码中集成","部分.
str_replace('_', ' ', $test)
Run Code Online (Sandbox Code Playgroud)
它会是这样的:
str_replace(('_', ' ',),(',', ' '), $test)
Run Code Online (Sandbox Code Playgroud) 我需要替换(使用jquery)未在document.ready上加载的元素的文本.该元素加载了ajax.
我尝试过:
$('#my-div label').live({
var text = $(this).text();
$(this).text(text.replace('text', 'my text'));
});
Run Code Online (Sandbox Code Playgroud)
HTML是类似的东西
<div id="my-div"><label>text</label></div>
Run Code Online (Sandbox Code Playgroud) 如何用链接替换标签的内容
$str = 'This <strong>string</strong> contains a <a href="/local/link.html">local link</a>
and a <a href="http://remo.te/link.com">remote link</a>';
$str = strip_tags($str,'<a>'); // strip out the <strong> tag
$str = ?????? // how can I strip out the local link anchor tag, but leave the remote link?
echo $str;
Run Code Online (Sandbox Code Playgroud)
期望的输出:
This string contains a local link and a <a href="http://remo.te/link.com">remote link</a>
Run Code Online (Sandbox Code Playgroud)
或者,更好的是,用其url替换远程链接的内容:
This string contains a local link and a http://remo.te/link.com
Run Code Online (Sandbox Code Playgroud)
我怎样才能达到最终输出?
我有一个ul由外部JavaScript生成的无序列表().在每个列表项中都有一条我想要删除的重复行.因为我无法修改外部javascript,我试图使用replace方法.该列表由给予每个li元素的类标识; rss-item.
以下是我的代码:
<script>
function myFunction() {
var str = document.getElementsByClassName('rss-item').innerHTML;
var res = str.replace('Text to replace', '');
document.getElementsByClassName('rss-item').innerHTML = res;
}
</script>
<button onclick="myFunction()">Replace</button>
Run Code Online (Sandbox Code Playgroud)
错误发生在以下行:
var res = str.replace('Text to replace', '');
Run Code Online (Sandbox Code Playgroud)
错误说明:
Uncaught TypeError: Cannot read property 'replace' of undefined
Run Code Online (Sandbox Code Playgroud)
据我所知,这可能意味着javascript要么找不到类名为'rss-item'的元素,要么找不到我想要替换的文本.我绝对肯定这是正确的类名,我试图替换的文本确实存在.是否出现此问题是因为标记是由javascript生成的?我走到了尽头.
我有一个表存储在SQL Server上的文件的表.我需要在最后一个反斜杠之前替换路径:
C:\ Users\APP\AppData\Local\Temp\test\abc deg.pdf
举例来说:
\ app\pp\abc deg.pdf
编辑:该表包含许多路径 - 我需要遍历整个表并更改所有路径.
str-replace ×10
php ×6
javascript ×2
jquery ×2
preg-replace ×2
replace ×2
css ×1
html ×1
list ×1
preg-match ×1
regex ×1
sql-server ×1
string ×1
strip-tags ×1
t-sql ×1