首页 \ 问答 \ 在第一个标记之前获取HTML(Getting HTML before first
tag)

在第一个标记之前获取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...

更新时间:2022-11-28 12:11

最满意答案

$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,但为了更好的兼容性,一些工具尽可能地发 ...
  • 从这个公认的答案: 哪些元素支持:: before和:: after伪元素? 正如你可以在这里阅读http://www.w3.org/TR/CSS21/generate.html ,: 仅适用于具有(文档树)内容的元素 。 没有内容,也没有
    。 不好笑,你有没有考虑过这样做的图像? content: url(image.jpg) 这个说法,我在之前用::设计了一个东西,用于悬停在锚点上的背景覆盖。 我必须指定css内容为空{content =“”} otherwize不显 ...
  • $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. ...
  • 只需
    就足够了。 其他形式与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 ...

相关文章

更多

最新问答

更多
  • 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
  • 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
  • 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
  • ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
  • Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
  • 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
  • 功能包装避免重复(wrap of functions avoid duplicating)
  • Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
  • 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
  • VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
  • 大学电脑四级对初学者来说要多久能过
  • 特殊字符删除?(Special characters remove?)
  • Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
  • 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
  • Javaweb开发,技术路线是什么?该怎么写?
  • JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
  • 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
  • Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
  • 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
  • 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
  • “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
  • maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
  • 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
  • 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
  • java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
  • 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
  • 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
  • 嵌套的模板可能性(Nested template possibilities)
  • 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
  • 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)