Jump to content


Photo

eregi_replace problem when string is a file


  • Please log in to reply
4 replies to this topic

#1 silentwf

silentwf
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 August 2006 - 01:00 PM

I'm trying to make a highlight replacing function just like GeSHi (but I need to mod it for my needs and stuff)
My code is:
<?php
$string = include("test.php");
$r = "<a href='whoknowswhat.html'>apples</a>";
$p = "apples";
$s2 = eregi_replace($p, $r, $string);
echo $s2;
?>
i THINK that my $s2 declaration has no problems and I think the problem resides in $string. Is my declaration incorrect, 'cause once I change $string into something like "I love to eat apples" or something, the eregi_replace function works like magic.

#2 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 05 August 2006 - 01:13 PM

very well noticed...

$string = include_once('test.php');// gives you zero, nada, ..
//but
$string = file_get_contents('test.php');// gives you it all....

go forth and code my padawan... :D

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 August 2006 - 01:46 PM

you cannot assign a variable the value of include as include doesnt return anything. If you want to get the contents of the file you'll want to use file_get_contents function which returns the contents of that file.

#4 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,430 posts
  • LocationBelgium

Posted 05 August 2006 - 02:59 PM

I wouldn't could have said it better myself...

#5 silentwf

silentwf
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 05 August 2006 - 11:38 PM

Ya, thanks guys. I happened to stumble over the idea maybe "file reading" would do.
Then I searched it up on php.net. It gave me that, but didnt work, and on the bottom it said "see also" and it gave me "file_get_contents"
So! Thanks for helping out ^^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users