3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getAnchorText($txt) { $openTag = '#a#'; $closeTag = '#/a#'; $offsetStart = strpos($txt, $openTag); if(false !== $offsetStart) { $offsetStart+= strlen($openTag); } else { $offsetStart = 0; } $offsetEnd = strpos($txt, $closeTag); if (false !== $offsetEnd) { $offsetLength = $offsetEnd - $offsetStart; } else { $offsetLength = strlen($txt); } return substr($txt, $offsetStart, $offsetLength); } $txt = 'Some text with #a#anchor end'; echo getAnchorText($txt);

preferences:
44.45 ms | 402 KiB | 5 Q