English 中文(简体)
关于定义清单的争论
原标题:regex question redux regarding definition list
  • 时间:2009-12-12 04:17:07
  •  标签:
  • php
  • regex

努力找出办法,在这种数据中排除没有任何价值的属性。 帮助。

感谢托马拉卡,我目前的戒律就是这样。

Regex

([^=|]+)=([^|]+)(?:||$)

附录一

<dt>$1</dt><dd>$2</dd>

数据显示了这一点。

Bristlematerial=material=Steel Dia.=4 : CTOC=4 Cleaning rust, volume and dirt, Light Deburring,nor Bl, Roughtion for adhesion, Finish preparation prior to plating or Papaending Applied Materials = ́pe, With=Straight Grinders, Corte/Pedestal Grinders, Right Angle Grinders 类型=每批包装材料=1。

最终结果就是这样。

 <dt>Wire Material</dt><dd>Steel</dd><dt>Dia.</dt><dd>4 in</dd><dt>Wire Size</dt><dd>0.0095 in</dd>

不详

 Bristle Material=|<dt>Wire Material</dt><dd>Steel</dd><dt>Dia.</dt><dd>4 in</dd>Grit=|Bristle Diam=|<dt>Wire Size</dt><dd>0.0095 in
最佳回答

这里,你如何在没有定期表达的情况下在公共卫生和社会福利部中这样做:

$parts_list = explode( | , "Bristle Material=|Wire M....");
$parts      = "";

foreach( $parts_list as $part ){
    $p = explode( = , $part);
    if(!empty($p[1])) $parts .= "<dt>$p[0]</dt>
<dd>$p[1]</dd>
";
}

echo $parts;

这里是你如何经常表达:

$parts = preg_replace( 
    array( /([^=|]*)=(?:||$)/ , /([^=|]*)=([^|]+)(?:||$)/ ),
    array(  ,  <dt>$1</dt><dd>$2</dd> ),
    $inputString 
);

echo $parts;

<>Update>

这里使用的是PHPpreg_replace的一个特殊替代特征,该特征包含一系列的格外表述和一系列替代体。 The array ( syntax of the行文基本上等同于:

If I can match this: /([^=|]*)=(?:||$)/ then replace it with an empty string.
If I can match this: /([^=|]*)=([^|]+)(?:||$)/ then replace it with <dt>$1</dt><dd>$2</dd>

为了在Reex编辑中测试这一版本,你将首先使用(/([>>>>/([>>>>>]=(?:<>>>>)。 接着是第一个表达结果的第二次表述。

问题回答
([^=|]*)=([^|]*)(?:||$)

a. 挖掘价值者,尝试:

(?:[^=|]*=|([^=|]*)=([^|]+))(?:||$)

参看preg_match。 页: 1

 preg_match_all( ~([^|]+)=([^|s][^|]*)~ , $str, $matches, PREG_SET_ORDER);
 foreach($matches as $match)
      echo "<dt>{$match[1]}</dt><dd>{$match[2]}</dd>
";




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签