473,783 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eregi or similar_text < -- problem either way

(driving me nuts)
Hi there. I wonder if anyone can help?

I'm including a page from Google in search.php, passing some
parameters. So far so good. Then I'm asking to look through that
Google page for a text match, and return true or false.
eregi returns false whatever the case,
similar_text returns true whatever the case.

Can someone sort me out - oops, HELP me out ?
Thanks thanks in advance !

(code)
$page="http://www.google.com/search$search";
// check to see if on page 1
$text="my_text_ here";
if (eregi('/\b$text/i', '$page')) {
echo "Match";
} else {
echo "No Match";
}
(/code)

OR

(code)
$page="http://www.google.com/search$search";
// check to see if on page 1
$text="my_text_ here";
if (similar_text('/\b$text/i', '$page')) {
echo "Match";
} else {
echo "No Match";
}
(/code)
Jul 17 '05 #1
5 2762
george wrote:
$page="http://www.google.com/search$search";
// check to see if on page 1
$text="my_text_ here";
if (eregi('/\b$text/i', '$page')) {
echo "Match";
} else {
echo "No Match";
}
Never matches.

You are checking for
a slash followed by a back slash, b, dollar sign, t, e, x, t, slash, i
in
dollar sign, p, a, g, e
If you want to check for
backslash, b, m, y, underscore, t, e, x, t, underscore, h, e, r, e
in
h, t, t, p, colon, slash, slash, ...

the right eregi() is
eregi('\b' . $text, $page)
The slashes and last "i" you put in the eregi are used for preg_*
functions (which are better than their ereg* counterparts).

$page="http://www.google.com/search$search";
// check to see if on page 1
$text="my_text_ here";
if (similar_text('/\b$text/i', '$page')) {
echo "Match";
} else {
echo "No Match";
}


In my tests I only managed to have similar_text() return 0 (false) with
similar_text('' , $something) or similar_text($s omething, '')
Any two non-empty strings will return at least 1 (true).

The strings you are comparing are here are
slash, backslash, b, dollar sign, t, ...
and
dollar sign, p, a, g, e

To compare
m, y, underscore, t, e, x, t, underscore, ...
and
h, t, p, p, colon, slash, slash, ...

the right similar_text() is
similar_text($t ext, $page)
NOTE: none of these "corrected" things will check whether
the *contents* of the web page contain whatever is in $text
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
george wrote:
if (eregi('/\b$text/i', '$page'))


A couple of important points:

(i) You're using a PCRE pattern in a POSIX function, and the
delimiters, assertion, variable and modifier aren't
understood.

(ii) You're expecting variable expansion in single-quotes, in at
least two places:
(a) the pattern parameter, and
(b) the subject parameter.

Ref.:

http://www.php.net/manual/en/function.preg-match.php

--
Jock
Jul 17 '05 #3
Thanks guys, especially Pedto, for being so lucid.

Neither worked though.

All I'm hoping to do is
1. include a webpage and display it <-- which is ok
2. Run down the page looking for a text string, and
3. If it's there display "Match found"

On my own attempts nothing works.

Neither:
if (similar_text($ text, $page)) {
-or-
if (eregi('\b' . $text, $page)) {

I have a quick nasty fix running using javascript but it's ugly.
Any further thoughts would be appreciated.

See ya
Jul 17 '05 #4
george wrote:
All I'm hoping to do is
1. include a webpage and display it <-- which is ok
Since you want the data for something more than just display it, do not
include it, instead put its contents in a variable

$URL = 'http://www.example.com/';
$contents = file_get_conten ts($URL); // see [1] below
// and now that the webpage is saved display it
echo $contents;

2. Run down the page looking for a text string, and
$text_string = 'text string';
if (stripos($conte nts, $text_string) !== false) { // see [2] below
3. If it's there display "Match found"


echo 'Match found';
}
[1] http://www.php.net/file_get_contents
use another method to get the file contents if your php < 4.3.0
fopen() and fread() should do it [don't forget fclose() if you
choose to use fopen()]

[2] http://www.php.net/stripos
stripos() performs a case insensitive search; if you need a case
sensitive search use strpos() instead
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5
THANK YOU PEDRO
...
Because the server is running <PHP5, I got an undefined function on stripos().
But this did the trick:

function stripos($conten ts, $text_string, $offset=0) {
return strpos(strtoupp er($contents), strtoupper($tex t_string), $offset);
}

if (stripos($conte nts, $text_string) !== false) {
echo "Match";
} else {
echo "Duh!";
}
Thank you very very much.
Bye
Jul 17 '05 #6

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

Similar topics

1
2383
by: fartsniff | last post by:
Hello all. I am starting to work on a URL "cleaner" of sorts. The code below is only checking for a few simple entries on the URL, but for some reason it is not replacing them with "" when found. $qs and $clean_qs produce the same results. Also, can someone who is fluent with regex stuff take a look at my eregi expressions ? Im not sure if this is the most efficient way of
5
6918
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the file name. I can successfully extract the TITLE section, but no luck with the AUTHOR part. Any idea why?
0
2090
by: renster | last post by:
Hi, I was wondering if anyone here had a decent solution to this mysql/php problem. I have a mysql database with a list of groups (group_id, group_name, group_location, group_time, group_day). group_name must be unique for each group_location - so there is only ever one particular group name per group location.
1
2125
by: Stephan Heckmueller | last post by:
Hallo, in der Dokumentation von o.g. Funktion wird eine Arbeit von Oliver aus dem Jahre 93 erwaehnt; kann mir jemand den genauen Titel mitteilen? In welcher Datei des PHP-Quellcodes ist die obige Funktion implementiert? danke. PS: Anworten bitte auch via eMail.
2
4034
by: Frank | last post by:
I'm having trouble detecting whitespaces in strings. Set up this test: echo "<br>example 1:".intval(eregi("^\s","teststring")); echo "<br>example 2:".intval(eregi("^\s","test string")); Both resulting in 0 (zero) also tried and without result
25
6509
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate $email = $_POST // Use John Coggeshalls script to validate the email address if(!eregi("^+(\.+)*@+(\.+)*(\.{2,3})$", $email) { echo "The e-mail was not valid";
1
1726
by: news | last post by:
God, I have read every comment in php.net eregi and Google searched, and I have tried so many different attempts...this is the closest I've gotten to verify a variable contains only: alphanumerics, spaces, underscore, hyphen, period, apostrophe if(eregi("^+$", $value)) { return true; }
4
2462
by: Nel | last post by:
Hi all, I am struggling with understanding a small eregi problem in php4. My code: <?PHP $htmlsource = '<img src="pics/hotdog.gif"> text text <img src="pics/silly%20sausage.gif"> '; eregi('(=")(pics/)(+...)(")',$htmlsource,$imagesintext); ?>
1
2029
by: fade2gray | last post by:
Hi, (new to group and a php novice) I'm editing some files using exapmles for reference. (1) // if (!eregi("admin.php", $_SERVER)) { die ("Access Denied"); } (2) if ( !defined('ADMIN_FILE') ){ die("Access Denied"); }
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.