使用php从内爆数据中删除第一个字符

问题描述:

I have the following code

<td class="t-value h6"><?php echo implode('<br> ', $datas);

this code dump result like this

a.first element<br>
B.seconds element<br>
c.third element <br>
d.etc

what I want is to hide the first and second character of each element I tried

<td class="t-value h6"><?php  
$datas = implode('<br/>', $datas);
echo substr($datas, 2);     

but that did work only for the first element and I want it to apply to all elements inside data

thanks verry mx

我有以下代码 p>

 &lt; td class =  “t-value h6”&gt;&lt;?php echo implode('&lt; br&gt;',$ datas); 
  code>  pre> 
 
 

此代码转储结果如下 p>

  a.first element&lt; br&gt; 
B.seconds element&lt; br&gt; 
c.third element&lt; br&gt; 
d.etc 
  code>   pre> 
 
 

我想要的是隐藏我尝试的每个元素的第一个和第二个字符 p>

 &lt; td class =“t-value  h6“&gt;&lt;?php 
 $ datas = implode('&lt; br /&gt;',$ datas); 
echo substr($ datas,2);  
  code>  pre> 
 
 

但这只适用于第一个元素,我希望它适用于数据中的所有元素 p>

谢谢你们 mx p> div>

You can use regex to do this work in preg_replace() function

$newDates = preg_replace("/^\w\./m", "", $dates)

Check result in demo

Work with each array element separately and then do implode.

$data2 = array();
foreach($datas as $d){
    $data2[] = substr($d, 2);
}
$data2 = implode('<br/>', $data2);

It is probably easier to use preg_replace for this, depending on your willingnes to use regexp.

For example this would solve the issue as long as you do not have the same pattern somewhere else.

$output = preg_replace("/\w\./", "", $datas);