3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //this code will append a &mobileapp to every https://example.com url and http://foobar.com url ob_start(); ?> <html> <head> </head> <body> <a href="http://foobar.com"> http://www.example.com/~hillybilly/foobar.php silly silly </body> </html> <?php $html = ob_get_clean(); $append = 'mobileapp'; $doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXpath($doc); $elements = $xpath->query('//*[@href | @src | @action]'); class RELAppender{ private $domains_to_append = array(); private $append_get = ''; private $no_domains = true; public function __construct($domains_to_append, $append_get, $no_domains = true){ $this->domains_to_append = $domains_to_append; $this->append_get = 'mobileapp'; } public function replace_url($url){ if ($this->no_domains){ if (strpos('http://', $url) === false && strpos('https://', $url) === false){ } } if (strpos('?', $url) !== false){ return $url .= '&'.$this->append_get }else{ return $url .= '?'.$this->append_get; } return $url; } } $rel = new RELAppender(array('http://example.com','https://example.org'),'mobileapp', true) if (!is_null($elements)) { foreach ($elements as $element) { var_dump($element); if ($element->hasAttribute('href')){ $url = $element->getAttribute('href'); $newurl = $rel->replace_url($url); $element->setAttribute('href', $newurl); } } } echo $doc->saveHtml();
Output for 5.3.0 - 5.4.24
Parse error: syntax error, unexpected '}' in /in/2rUTv on line 42
Process exited with code 255.