Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eregi problems

Status
Not open for further replies.

barryturrell

Technical User
Joined
Oct 5, 2001
Messages
4
Location
GB
i am having an eregi prob

basically How do u use it?

I have:

if (eregi("correction, correction2", $file[$i])) {

^ ^ ^
replace this with this in this file

can any i help?
 
ereg() is a "find" function used if you want to match a pattern, and ereg_replace() is a replace function. The "i" just ignores case. In other words, if you just want to find out if an email address is in the correct format:

if (ereg("^(.+)@(.+)\\.(.+)$", $email)
echo "Email is valid";
else
echo "Email is not valid";

But if you want to replace a pattern with another one (in this case change "hello there" to "HellO there"):

echo ereg_replace("h(ell)o", "H\\1O", "hello there");

Does that help?
 
Of sorts, thanx

How would u get it to replace A value of Y with a value of X ( x and y could be any numeric value)

So it writes to a file "video.txt" and replaces value X with value Y

eg:

x=1
y=2

so 1 would be replaced with 2 in the file.

Can u help?

thanx
 
So are you saying you want to replace all "1" with "2" and write the result to video.txt? If so:

$inputStr = "There is a 1 in this string.";
$outputStr = ereg_replace("1", "2", $inputStr);
$fp = fopen("video.txt", "w");
fwrite($fp, "$outputStr");
fclose($fp);
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top