{foreach from=$breadcrumbsList item=e name=bc}
и тогда можем воспользоваться переменными цикла content="{$smarty.foreach.bc.iteration}"
./**
* Date: 05.05.17
* Time: 17:42
*/
namespace app\components;
/**
* Class UrlGrabberService
* @package app\components
*/
class UrlGrabberService
{
public $newLink = [];
public $savedLink = [];
public $siteUrl = false;
/**
* @return static
*/
public static function getInstance(){
return new static();
}
/**
* @param $url
* @return array
*/
public function getAllLinkBySite($url){
$this->newLink = $this->getAllLinkByUrl($url);
while(!empty($this->newLink)){
$link = array_shift($this->newLink);
$this->savedLink[] = $link;
$this->addLinkByUrl($link);
}
return $this->savedLink;
}
/**
* @param $url
* @return array
*/
protected function getAllLinkByUrl($url){
$pattern = '/<a[\s\W]*?href\S*?=\S*?[\'"](\/\w.*?)\/?[\'"]/';
$headers = @get_headers($url);
if(strpos($headers[0],'200')===false){
$result = [];
}
else{
$opts = array('https'=>array('header' => "User-Agent:MyAgent/1.0\r\n"));
$context = stream_context_create($opts);
$content = \file_get_contents($url,false,$context);
$matches = [];
preg_match_all($pattern,$content,$matches);
$result = array_unique($matches[1]);
}
return $result;
}
/**
* @param $url
*/
protected function addLinkByUrl($url){
$this->newLink = array_merge($this->newLink,$this->getAllLinkByUrl($this->siteUrl . $url));
$this->newLink = array_unique($this->newLink);
$this->newLink = array_diff($this->newLink, $this->savedLink);
}
}
$result = UrlGrabberService::getInstance()->getAllLinkBySite('http://example.com');