Solved

correctly using eregi

Posted on 2009-05-06
8
202 Views
Last Modified: 2012-05-06
hello there,
im trying to show done if the $post has any word from the array but its not working on..
what can I do about this?
<?
$Post='the pages has finished downloading';
$regex = array('sucess','completed','finished');
if(eregi($regex, $Post)) {
	echo 'done';
}else{
	echo 'error';
}
?>

Open in new window

0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 5

Expert Comment

by:synx
ID: 24317308
Here's the PHP manual for eregi: http://us3.php.net/eregi

Note that the first parameter that it's expecting is a string.  You are passing an array of strings.  Can you just check like this?


<?
$Post='the pages has finished downloading';
$regex = 'finished';
if(eregi($regex, $Post)) {
        echo 'done';
}else{
        echo 'error';
}
?>

Open in new window

0
 
LVL 5

Expert Comment

by:synx
ID: 24317334
You may also be able to just put all of the things you want to search for in one big string.  Like:
<?
$Post='the pages has finished downloading';
$regex = 'success completed finished';
if(eregi($regex, $Post)) {
        echo 'done';
}else{
        echo 'error';
}
?>

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 24317358
these are key string that will decide if its success or fail

'successfully submitted'
'Thank you for submitting'
'submitted successfully'

how can I search the data and if any of those are found to echo success?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 5

Expert Comment

by:synx
ID: 24317425
Try this:

<?php
$regex = array('successfully submitted','Thank you for submitting','submitted successfully');
$success = 0;
;
foreach ($regex as $value) {
	if(eregi($value, $Post)) {
      echo 'success';
	  $success = 1;
	  break;
    }
}
if($success==0) {
  echo 'error';
}
 
?>

Open in new window

0
 
LVL 5

Expert Comment

by:synx
ID: 24317432
sorry about the spacing on that code snippet.
0
 
LVL 5

Expert Comment

by:synx
ID: 24317441
Sorry - forgot your "Post" line:
<?php
$Post='the pages has finished downloading';
$regex = array('successfully submitted','Thank you for submitting','submitted successfully');
$success = 0;
;
foreach ($regex as $value) {
  if(eregi($value, $Post)) {
    echo 'success';
	$success = 1;
	break;
  }
}
if($success==0) {
  echo 'error';
}
 
?>

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 24317494
it is showing 3 sucess.. it should show only one since $post changes.. if post has it sucess else error
0
 
LVL 5

Accepted Solution

by:
synx earned 500 total points
ID: 24317541
How about:
<?php
$Post='the pages has finished downloading';
$regex = array('successfully submitted','Thank you for submitting','submitted successfully');
$success = 0;
;
foreach ($regex as $value) {
  if(eregi($value, $Post)) {
    $success = 1;
  }
}
if($success==0) {
  echo 'error';
} else {
  echo 'success!';
}
 
?>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question