473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

handling warnings, php5?

Hi.
I need to handle warnings in incorrect regular expressions executed
using preg_match.
Warnings shouldn't appear, instead I want to output some generic
message like: "Bad regex: $regex" and also do a database change.
I tried using try-catch but warnings are not caught.
What do I do?

Jun 10 '07 #1
2 2192
At Sun, 10 Jun 2007 05:36:11 -0700, Sergei Shelukhin let h(is|er) monkeys
type:
Hi.
I need to handle warnings in incorrect regular expressions executed
using preg_match.
Warnings shouldn't appear, instead I want to output some generic
message like: "Bad regex: $regex" and also do a database change.
I tried using try-catch but warnings are not caught.
What do I do?
You can suppress warnings by setting the proper error_reporting() level
(see manual), or by prepending your function call with @.

Then check for the returned value by the regex function and use
trigger_error('Your message',E_USER_WARNING). (Again, see manual for
details)

if (! @preg_match($pattern,$string,$match_arr) {
trigger_error ('Blahblah', E_USER_WARNING);
}

--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 10 '07 #2
On 10.06.2007 14:36 Sergei Shelukhin wrote:
Hi.
I need to handle warnings in incorrect regular expressions executed
using preg_match.
Warnings shouldn't appear, instead I want to output some generic
message like: "Bad regex: $regex" and also do a database change.
I tried using try-catch but warnings are not caught.
What do I do?
The "natural" way is to use exceptions. First, install generic
errors-to-exceptions handler (see Exceptions man page). Then, just
enclose preg code in a try-catch block:

try {
preg_match($regex, ...)
} catch(ErrorException $e) {
echo "Bad regex: $regex";
}

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Jun 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chung Leong | last post by:
Help me here. I've become a bitconfused about how PHP4 deals with objects after reading this description of PHP5: "PHP's handling of objects has been completely rewritten, allowing for better...
8
by: Rob Ristroph | last post by:
I have tried out PHP 5 for the first time (with assistance from this group -- thanks!). The people I was working with have a site that uses lots of php objects. They are having problems with...
1
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting my applications to PHP5 and I've stumbled on yet another problem. I'll try to simplify things a bit. I have a main script that is being executed (index.php, PHP5...
1
by: Mike | last post by:
Last weekend I decided to install Apache 2.0.53-win32-x86-no_ssl PHP 5.0.3 Smarty 2.6.7 MySQL essential-4.1.10-win32 I have Apache up (Port 80 blocked at the router and firewall!) and I have...
3
by: Ian Collins | last post by:
I've just moved to 5.1.2 from 5.0.5 and I'm getting these warnings for each and every query: PHP Notice: Object of class DB_result could not be converted to int in...
2
by: al3x4nder | last post by:
I`m need hanling XSLT errors in my script, before I`m use Sablotron, that has nice interface for it: ------------8<------------------ function ProduceXHTML($xml, $xsl){ $xh = xslt_create();...
1
by: Vivek | last post by:
Hi, This is a very general problem which iam sure application programmers all over have faced. How does one handle the warnings that DB2 issues ? Should they be ignored or treated the same as...
5
by: simon m | last post by:
Hi All, I have a script sitting on my web server called auto_mail.php5. I would like this to be used two different ways. One way would be for a web form to call it as submit action on a form. I...
5
by: kellygreer1 | last post by:
I think I'm not quite understanding something about error handling in PHP5. I have written some PHP code to index the contents of C drive on a Windows machine. When it gets to certain special...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.