@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | HTML; |
| 16 | 16 | |
| 17 | 17 | $html = HtmlDomParser::str_get_html($str); |
| 18 | -echo $html->find('div div div', 0)->innertext . '<br>'; // result: "ok" |
|
| 18 | +echo $html->find('div div div', 0)->innertext.'<br>'; // result: "ok" |
|
| 19 | 19 | |
| 20 | 20 | // ----------------------------------------------------------------------------- |
| 21 | 21 | // nested selector |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $html = HtmlDomParser::str_get_html($str); |
| 34 | 34 | foreach ($html->find('ul') as $ul) { |
| 35 | 35 | foreach ($ul->find('li') as $li) { |
| 36 | - echo $li->innertext . '<br>'; |
|
| 36 | + echo $li->innertext.'<br>'; |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | $html = HtmlDomParser::str_get_html($str); |
| 51 | 51 | foreach ($html->find('input[type=checkbox]') as $checkbox) { |
| 52 | 52 | if ($checkbox->checked) { |
| 53 | - echo $checkbox->name . ' is checked<br>'; |
|
| 53 | + echo $checkbox->name.' is checked<br>'; |
|
| 54 | 54 | } else { |
| 55 | - echo $checkbox->name . ' is not checked<br>'; |
|
| 55 | + echo $checkbox->name.' is not checked<br>'; |
|
| 56 | 56 | } |
| 57 | 57 | } |
@@ -9,36 +9,36 @@ |
||
| 9 | 9 | |
| 10 | 10 | // find all link |
| 11 | 11 | foreach ($html->find('a') as $e) { |
| 12 | - echo $e->href . '<br>'; |
|
| 12 | + echo $e->href.'<br>'; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | // find all image |
| 16 | 16 | foreach ($html->find('img') as $e) { |
| 17 | - echo $e->src . '<br>'; |
|
| 17 | + echo $e->src.'<br>'; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | // find all image with full tag |
| 21 | 21 | foreach ($html->find('img') as $e) { |
| 22 | - echo $e->outertext . '<br>'; |
|
| 22 | + echo $e->outertext.'<br>'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // find all div tags with id=gbar |
| 26 | 26 | foreach ($html->find('div#gbar') as $e) { |
| 27 | - echo $e->innertext . '<br>'; |
|
| 27 | + echo $e->innertext.'<br>'; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // find all span tags with class=gb1 |
| 31 | 31 | foreach ($html->find('span.gb1') as $e) { |
| 32 | - echo $e->outertext . '<br>'; |
|
| 32 | + echo $e->outertext.'<br>'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // find all td tags with attribite align=center |
| 36 | 36 | foreach ($html->find('td[align=center]') as $e) { |
| 37 | - echo $e->innertext . '<br>'; |
|
| 37 | + echo $e->innertext.'<br>'; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // extract text from table |
| 41 | -echo $html->find('td[align="center"]', 1)->plaintext . '<br><hr>'; |
|
| 41 | +echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>'; |
|
| 42 | 42 | |
| 43 | 43 | // extract text from HTML |
| 44 | 44 | echo $html->plaintext; |
@@ -710,7 +710,7 @@ |
||
| 710 | 710 | * |
| 711 | 711 | * @param string $name <p>The name of the html-attribute.</p> |
| 712 | 712 | * |
| 713 | - * @return mixed |
|
| 713 | + * @return SimpleHtmlDom |
|
| 714 | 714 | */ |
| 715 | 715 | public function removeAttribute(string $name) |
| 716 | 716 | { |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | $tmpStr = $this->normalizeStringForComparision($string); |
| 501 | 501 | if ($tmpDomString !== $tmpStr) { |
| 502 | 502 | throw new RuntimeException( |
| 503 | - 'Not valid HTML fragment!' . "\n" . |
|
| 504 | - $tmpDomString . "\n" . |
|
| 503 | + 'Not valid HTML fragment!'."\n". |
|
| 504 | + $tmpDomString."\n". |
|
| 505 | 505 | $tmpStr |
| 506 | 506 | ); |
| 507 | 507 | } |
@@ -547,8 +547,8 @@ discard block |
||
| 547 | 547 | $tmpStr = $this->normalizeStringForComparision($string); |
| 548 | 548 | if ($tmpDomOuterTextString !== $tmpStr) { |
| 549 | 549 | throw new RuntimeException( |
| 550 | - 'Not valid HTML fragment!' . "\n" |
|
| 551 | - . $tmpDomOuterTextString . "\n" . |
|
| 550 | + 'Not valid HTML fragment!'."\n" |
|
| 551 | + . $tmpDomOuterTextString."\n". |
|
| 552 | 552 | $tmpStr |
| 553 | 553 | ); |
| 554 | 554 | } |
@@ -446,10 +446,10 @@ |
||
| 446 | 446 | '/(?<start>.*)<(?<element_start>[a-z]+)(?<element_start_addon> [^>]*)?>(?<value>.*?)<\/(?<element_end>\2)>(?<end>.*)/sui', |
| 447 | 447 | function ($matches) { |
| 448 | 448 | return $matches['start'] . |
| 449 | - '°lt_simple_html_dom__voku_°' . $matches['element_start'] . $matches['element_start_addon'] . '°gt_simple_html_dom__voku_°' . |
|
| 450 | - $matches['value'] . |
|
| 451 | - '°lt/_simple_html_dom__voku_°' . $matches['element_end'] . '°gt_simple_html_dom__voku_°' . |
|
| 452 | - $matches['end']; |
|
| 449 | + '°lt_simple_html_dom__voku_°' . $matches['element_start'] . $matches['element_start_addon'] . '°gt_simple_html_dom__voku_°' . |
|
| 450 | + $matches['value'] . |
|
| 451 | + '°lt/_simple_html_dom__voku_°' . $matches['element_end'] . '°gt_simple_html_dom__voku_°' . |
|
| 452 | + $matches['end']; |
|
| 453 | 453 | }, |
| 454 | 454 | $html |
| 455 | 455 | ); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | return \call_user_func_array([$this, self::$functionAliases[$name]], $arguments); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - throw new \BadMethodCallException('Method does not exist: ' . $name); |
|
| 170 | + throw new \BadMethodCallException('Method does not exist: '.$name); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -318,14 +318,14 @@ discard block |
||
| 318 | 318 | self::$domReplaceHelper['orig'] |
| 319 | 319 | ); |
| 320 | 320 | |
| 321 | - $DOM_REPLACE__HELPER_CACHE['tmp']['html_wrapper__start'] = '<' . self::$domHtmlWrapperHelper . '>'; |
|
| 322 | - $DOM_REPLACE__HELPER_CACHE['tmp']['html_wrapper__end'] = '</' . self::$domHtmlWrapperHelper . '>'; |
|
| 321 | + $DOM_REPLACE__HELPER_CACHE['tmp']['html_wrapper__start'] = '<'.self::$domHtmlWrapperHelper.'>'; |
|
| 322 | + $DOM_REPLACE__HELPER_CACHE['tmp']['html_wrapper__end'] = '</'.self::$domHtmlWrapperHelper.'>'; |
|
| 323 | 323 | |
| 324 | 324 | $DOM_REPLACE__HELPER_CACHE['orig']['html_wrapper__start'] = ''; |
| 325 | 325 | $DOM_REPLACE__HELPER_CACHE['orig']['html_wrapper__end'] = ''; |
| 326 | 326 | |
| 327 | - $DOM_REPLACE__HELPER_CACHE['tmp']['html_special_script__start'] = '<' . self::$domHtmlSpecialScriptHelper; |
|
| 328 | - $DOM_REPLACE__HELPER_CACHE['tmp']['html_special_script__end'] = '</' . self::$domHtmlSpecialScriptHelper . '>'; |
|
| 327 | + $DOM_REPLACE__HELPER_CACHE['tmp']['html_special_script__start'] = '<'.self::$domHtmlSpecialScriptHelper; |
|
| 328 | + $DOM_REPLACE__HELPER_CACHE['tmp']['html_special_script__end'] = '</'.self::$domHtmlSpecialScriptHelper.'>'; |
|
| 329 | 329 | |
| 330 | 330 | $DOM_REPLACE__HELPER_CACHE['orig']['html_special_script__start'] = '<script'; |
| 331 | 331 | $DOM_REPLACE__HELPER_CACHE['orig']['html_special_script__end'] = '</script>'; |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | || |
| 416 | 416 | $this->keepBrokenHtml |
| 417 | 417 | ) { |
| 418 | - $html = '<' . self::$domHtmlWrapperHelper . '>' . $html . '</' . self::$domHtmlWrapperHelper . '>'; |
|
| 418 | + $html = '<'.self::$domHtmlWrapperHelper.'>'.$html.'</'.self::$domHtmlWrapperHelper.'>'; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | $html = self::replaceToPreserveHtmlEntities($html); |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | $xmlHackUsed = false; |
| 430 | 430 | if (\stripos('<?xml', $html) !== 0) { |
| 431 | 431 | $xmlHackUsed = true; |
| 432 | - $html = '<?xml encoding="' . $this->getEncoding() . '" ?>' . $html; |
|
| 432 | + $html = '<?xml encoding="'.$this->getEncoding().'" ?>'.$html; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | $this->document->loadHTML($html, $optionsXml); |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | |
| 471 | 471 | if (isset($specialScripts[0])) { |
| 472 | 472 | foreach ($specialScripts[0] as $specialScript) { |
| 473 | - $specialNonScript = '<' . self::$domHtmlSpecialScriptHelper . substr($specialScript, strlen('<script')); |
|
| 474 | - $specialNonScript = substr($specialNonScript, 0, -strlen('</script>')) . '</' . self::$domHtmlSpecialScriptHelper . '>'; |
|
| 473 | + $specialNonScript = '<'.self::$domHtmlSpecialScriptHelper.substr($specialScript, strlen('<script')); |
|
| 474 | + $specialNonScript = substr($specialNonScript, 0, -strlen('</script>')).'</'.self::$domHtmlSpecialScriptHelper.'>'; |
|
| 475 | 475 | |
| 476 | 476 | $html = \str_replace($specialScript, $specialNonScript, $html); |
| 477 | 477 | } |
@@ -490,11 +490,11 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | $html = (string) \preg_replace_callback( |
| 492 | 492 | '/(?<start>.*)<(?<element_start>[a-z]+)(?<element_start_addon> [^>]*)?>(?<value>.*?)<\/(?<element_end>\2)>(?<end>.*)/sui', |
| 493 | - function ($matches) { |
|
| 494 | - return $matches['start'] . |
|
| 495 | - '°lt_simple_html_dom__voku_°' . $matches['element_start'] . $matches['element_start_addon'] . '°gt_simple_html_dom__voku_°' . |
|
| 496 | - $matches['value'] . |
|
| 497 | - '°lt/_simple_html_dom__voku_°' . $matches['element_end'] . '°gt_simple_html_dom__voku_°' . |
|
| 493 | + function($matches) { |
|
| 494 | + return $matches['start']. |
|
| 495 | + '°lt_simple_html_dom__voku_°'.$matches['element_start'].$matches['element_start_addon'].'°gt_simple_html_dom__voku_°'. |
|
| 496 | + $matches['value']. |
|
| 497 | + '°lt/_simple_html_dom__voku_°'.$matches['element_end'].'°gt_simple_html_dom__voku_°'. |
|
| 498 | 498 | $matches['end']; |
| 499 | 499 | }, |
| 500 | 500 | $html |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $html = (string) \preg_replace_callback( |
| 508 | 508 | '/(?<start>[^<]*)?(?<broken>(?:(?:<\/\w+(?:\s+\w+=\\"[^\"]+\\")*+)(?:[^<]+)>)+)(?<end>.*)/u', |
| 509 | - function ($matches) { |
|
| 509 | + function($matches) { |
|
| 510 | 510 | $matches['broken'] = \str_replace( |
| 511 | 511 | ['°lt/_simple_html_dom__voku_°', '°lt_simple_html_dom__voku_°', '°gt_simple_html_dom__voku_°'], |
| 512 | 512 | ['</', '<', '>'], |
@@ -514,9 +514,9 @@ discard block |
||
| 514 | 514 | ); |
| 515 | 515 | |
| 516 | 516 | self::$domBrokenReplaceHelper['orig'][] = $matches['broken']; |
| 517 | - self::$domBrokenReplaceHelper['tmp'][] = $matchesHash = '____simple_html_dom__voku__broken_html____' . \crc32($matches['broken']); |
|
| 517 | + self::$domBrokenReplaceHelper['tmp'][] = $matchesHash = '____simple_html_dom__voku__broken_html____'.\crc32($matches['broken']); |
|
| 518 | 518 | |
| 519 | - return $matches['start'] . $matchesHash . $matches['end']; |
|
| 519 | + return $matches['start'].$matchesHash.$matches['end']; |
|
| 520 | 520 | }, |
| 521 | 521 | $html |
| 522 | 522 | ); |