-1

我试着剪断我的绳子,把所有东西都拿走,直到你找到“”

$ret = $html->find('td[class="date"]'); 

$pole = array();
foreach ($ret as $pole) {
    $datum[] = $pole->innertext;    // getting text what i need from HTML(simple html dom)
    }   

   echo "$datum[0]";    //output of this is: 04.07.2013 Film Europe 


$text_arr = str_split($datum[0]);      //string to array
foreach($text_arr as $x){

if($x==" ") break;   //if find space stop!
echo $x;
}

我是 100% 我的代码是正确的,但是它不起作用, echo $x 什么都不做 :),就像那个变量中没有存储任何东西一样

4

3 回答 3

1

以这种方式使用explode会更好:

$text_arr = explode(" ", $datum[0]);
echo $text_arr[0]; 

忘记 foreach 循环,只需使用第一个元素,因为它已经在第一个空格上剪切。

希望这可以帮助。

于 2013-07-22T22:25:31.160 回答
1

更简单的版本

$datum[0]="04.07.2013 Film Europe"; 
$x=explode(' ',trim($datum[0]));
echo $x[0]; //04.07.2013
于 2013-07-22T22:26:15.680 回答
0

实际上,您应该检查字符串是否包含您想要的内容。(例如,开头可能有一个无意义的空间......)

检查http://php.net/manual/de/function.preg-match.php

于 2013-07-22T23:17:36.587 回答