Take a look at this post : Get substring between two strings PHP
For your special case, I would suggest you to do as follow :
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
$fullstring = '<form action="../?x=3O1*qY*E-dEItGGem1mH3VN5Nm6cO0hiQkOl0nSasIQqTDPzbSUbCI3UYWGGhwZ0" id="id8" method="post">';
$parsed = get_string_between($fullstring, 'action="', '"');
echo $parsed; // result
You can also use a DOMParser :
$html = '<form action="../?x=3O1*qY*E-dEItGGem1mH3VN5Nm6cO0hiQkOl0nSasIQqTDPzbSUbCI3UYWGGhwZ0" id="id8" method="post">';
$d = new DomDocument();
$d>loadHTML($html);
$forms = $d->getElementsByTagName('form');
foreach ($forms as $key => $f){
echo $f->getAttribute('action');
}
EDIT : As suggested by Mikel Bitson, the DomParser method is cleaner and will work if there is more than one form.