在第一个标记之前获取HTML(Getting HTML before first
tag)
我一直试图在php中出现第一个中断标记之前提取变量的内容。
例如
$content = "this is my content <br /> as it continues <br /> another break tag";
我想在第一个之前得到部分
标记并将其存储在变量$ first中。 因此,对于上面的例子,$首先应该包含“这是我的内容”任何想法如何在PHP中做到这一点? 我坚持使用split()php函数...
I've been trying to extract the content of a variable before the first break tag occurs in php.
e.g
$content = "this is my content <br /> as it continues <br /> another break tag";
I want to get the part before the first
tag and store it in a variable $first. Thus for the above example, $first should contain "this is my content"Any idea how to do this in php? I'm stuck with the split() php function...
最满意答案
$content = "this is my content <br /> as it continues <br /> another break tag"; $parts = explode("<br />", $content); $first = trim($parts[0]);
爆炸功能: http : //php.net/manual/en/function.explode.php
按字符串拆分字符串
修剪功能: http : //www.php.net/manual/en/function.trim.php
从字符串的开头和结尾剥去空格
$content = "this is my content <br /> as it continues <br /> another break tag"; $parts = explode("<br />", $content); $first = trim($parts[0]);
explode function: http://php.net/manual/en/function.explode.php
Split a string by string
trim function: http://www.php.net/manual/en/function.trim.php
Strip whitespace from the beginning and end of a string
相关问答
更多-
这两种都适用于HTML。 虽然不适用于XML方言的XHTML。 一些元素不需要关闭( /> )标签 - 特别是空元素(那些没有内容的元素)。 例子是
和
。 这些也可以是自动关闭(分别为
和
)。 这种自动关闭相当于在打开标签后立即有一个关闭标签。 对于XML来说,这样一个非结束标签是无效的 - 它必须关闭,要么是自动关闭标签,要么是结束标签。 所以
不是有效的XML,但
和
是。 HTML不是XML,但为了更好的兼容性,一些工具尽可能地发 ... -
和::之后或::之前(
and ::after or ::before)[2022-04-22]从这个公认的答案: 哪些元素支持:: before和:: after伪元素? 正如你可以在这里阅读http://www.w3.org/TR/CSS21/generate.html ,: 仅适用于具有(文档树)内容的元素 。 没有内容,也没有或
。 不好笑,你有没有考虑过这样做的图像? content: url(image.jpg) 这个说法,我在之前用::设计了一个东西,用于悬停在锚点上的背景覆盖。 我必须指定css内容为空{content =“”} otherwize不显 ... -
在第一个标记之前获取HTML(Getting HTML before first
tag)[2022-11-28]$content = "this is my content
as it continues
another break tag"; $parts = explode("
", $content); $first = trim($parts[0]); 爆炸功能: http : //php.net/manual/en/function.explode.php 按字符串拆分字符串 修剪功能: http : //www.php.net/manual/en/function. ... -
HTML 5:是
,
还是
?(HTML 5: Is it
,
, or
?)[2022-04-22]只需
就足够了。 其他形式与XHTML兼容; 使得可以编写与XHTML相同的代码,并且还可以使用HTML。 生成HTML的一些系统可能基于XML生成器,因此无法仅输出一个裸的
标签; 如果您使用这样的系统,可以使用“好”,如果您不需要这样做,那就没有必要了。 然而,很少有人实际使用XHTML。 您需要将application/xhtml+xml内容提供给application/xhtml+xml ,以将其解释为XHTML,并且在旧版本的IE中不起作用 - 这也意味着您所做的任何小错误将阻止您的页 ... -
回答了自己。 element.xpath('text()')返回我正在寻找的两件事的数组。 Answered myself. element.xpath('text()') returns an array of both things I'm looking for.
-
因为
是一个void标记 (意思是它不能包含任何内容),你可以使用它作为
或者(尾随/将被忽略),但是
是无效 。 如果您希望标记是有效的XML,那么请使用
,但这与HTML解析器无关。 根据(最新) HTML5规范,这部分元素 。 Since
is a void tag (meaning it cannot wrap any content inside), you can either use it as
or
(the traili ... -
看看stackoverflow页面,
:) 干杯。 have a look at the stackoverflow page,...
:) cheers....
-
一个非常简单的方法,只需更改您的replaceAll的订单 text = text.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("\r\n", "
"); 这应该适用于你所问的问题 A very simple way, just change the orders of your replaceAll text = text.replaceAll("<", "<"); ... -
将文本放在带有前面的|的新行上 : table tbody tr td Juan Perez td 01 33 4455 6677 td Av José Vasconcelos 804-A Pte. br | Col. Los Sabinos,CP. 66220, San Pedro, N.L. 您还可以将两个文本节点放在新行上以提高可读性: table tbody tr td Juan Perez ...
-
正则表达式将是: <[^>]*>([^<]*) <[^>]*> - 数学thiw第一个标签“<...>” ([^<]*) - 捕获文本以打开下一个标记“<...> 一些文本 <...>” 如何将他应用于Rubby - 我不知道 看http://www.regular-expressions.info/ruby.html Regex will be: <[^>]*>([^<]*) <[^>]*> - math thiw first tag "<...>" ([^<]*) - capture text to o ...