【问题标题】:removal of a date in the text using regex or alternative small scripts使用正则表达式或替代小脚本删除文本中的日期
【发布时间】:2013-06-09 13:56:32
【问题描述】:
$string="18 Mar 2013 <b>...</b> And this is exactly what is sparking the resurgence of long-tail <br>  <b>keyword</b> targeting in <b>SEO</b>. I've observed this trend among both young <b>...</b>"
$string="May be <b>google</b> not considering Meta <b>keywords</b> for his searching, but meta <br>  descriptions play a vital role in your <b>SEO</b> practices,even including <b>...</b>"
$string="7 Jun 2010 <b>...</b> Picking <b>SEO Keywords</b>: Using <b>Google's</b> Wonder Wheel. This is in my opinion the <br>  best little secret of everyone's favorite search engine: the <b>...</b>"
$string="For search engine marketers -- and the companies who depend on them -- things <br>  just got a little tougher. <b>SEO</b> companies, most still reeling <b>...</b>"

$clean_string = preg_replace("need this here remove date regex syntax", "", $string);

需要一个正则表达式或一个小代码。请参阅上面的示例代码。删除文本开头的日期。。与更改文本和日期不同。我没有在某些文本开头的示例中注明日期。先谢谢各位朋友的帮助

【问题讨论】:

  • 这是您期望的唯一日期格式吗?或者也可以有类似01/01/99 的东西?
  • 2013 年 3 月 18 日,2010 年 6 月 7 日,bla balaa -- 看起来与谷歌搜索结果的日期相同。这些文字来自谷歌

标签: php regex string replace preg-replace


【解决方案1】:

这应该足以满足您示例中显示的日期格式:

$result = preg_replace(
    '/^      # Start of string
    \d{1,2}  # 1-2 digits
    \s+      # whitespace
    [a-z]+   # 1 or more ASCII letters
    \s+      # whitespace
    \d{2,4}  # 2-4 digits
    \s*      # optional whitespace/ix', 
    '', $subject);

【讨论】:

  • 谢谢蒂姆; İts 工作...我做了小修改 [a-zÄŸÅ]+ # 1 个或多个 ASCII 字母土耳其 ğ 和 Ş char (Ağu->Agust, Şub->February Month Special mod..)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-16
  • 1970-01-01
  • 2012-06-22
  • 2012-03-14
相关资源
最近更新 更多