Reputation: 598
i have this string :
Le serveur a retourné une erreur "500 An exception occurred while executing 'select DIVISIONTEST(4,0) from dual': SQLSTATE[HY000]: General error: 20000 OCIStmtExecute: ORA-20000: Bien essayé! ORA-06512: à "FOO.DIVISIONTEST", line 8 (ext\pdo_oci\oci_statement.c:148)".
i would like to show only this part : Bien essayé!
nothing before or after this part.
This string is generated by a:
$exception->getMessage()
Can you help me with a regex ? thanks you
EDIT : sorry , the customized message will change. I should have been more precise. I'm looking for a way to get the message after ORA-20000:
and before the ORA:
following .
I'm trying to get exception raised from a PL/SQL request. The error raised is a customized message
Upvotes: 0
Views: 142
Reputation: 46
Edit: updated after original post changed:
$re = '/OCIStmtExecute: ORA-[0-9]+: (.+) ORA-[0-9]+:/';
$subject = $exception->getMessage();
preg_match($re, $subject, $matches);
print_r($matches);
Upvotes: 0
Reputation: 332
<?php
if (preg_match("/Bien essayé!/i",$exception->getMessage())
echo : "Bien essayé!";
else
echo "Pas bien essayé :-D ";
?>
Upvotes: -1
Reputation: 2208
Well since you only want to match one case, you could use: preg_match
See PHP Manual: https://www.php.net/preg_match
Example:
$subject = $exception->getMessage();
$pattern = '/Bien essayé!/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
Upvotes: 3