PDA

View Full Version : PHP strrchar


Markpyro
08-18-2006, 8:16 PM
edit (I realize that I spelled the function wrong in the title, I know it's not supposed to be spelled that way)

I have a php file, that when you start it, finds data from a text file, and is supposed to find the last line of text (appears as last line when presented in html, as is divided by <br>'s) and put it into an image.

Here's a snippet that I'm having problems with:

$data=fread($o,filesize($filename));
$find = '>';
$string = $data; // Data is set at this point
$string = strrchr($data,$find); // Poof! Gone!
$string = ShortenText($string);


Okay, here's the definition via PHP.Net of the function, Strrchr:

strrchr -- Find the last occurrence of a character in a string,
This function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.


Now, when If I echo $data before it's modified, it looks fine. Once I apply the function to it, though, it dissapears. I just want to gather a portion of $data, the last line, and display it in an image. But, for some reason, strrchr doesnt output anything. Wtf?


-MP

TimP
08-18-2006, 9:50 PM
I did some quick tests and if the second parameter of strrchr doesn't exist, strrchr won't output anything. Without any sample data that doesn't work though, it's impossible to debug.

Jeff
08-19-2006, 7:10 AM
I don't know why your code doesn't work (I've never used strrchr), but here's how I would do it.


$data = file_get_contents("filename.txt");
$items = explode("<br>", $data);
$thelastline = end($items);


That should work fine but may take longer... though I doubt you'll notice unless your file is big.

Markpyro
08-19-2006, 6:47 PM
Thanks a bunch, I got it to work now ^_^

One more thing- is there a way I can run a PHP file from a different PHP file? This script that I just fixed updates an image, but I want it to go in my signiture. Since I cant link PHP files in my signiture, I'd like every time I open a different file for the first to run and update the image.

Jeff
08-19-2006, 7:00 PM
It may be possible to do that using curl (http://us2.php.net/curl), but I don't know enough about curl to be of much help there. Good luck if you give it a try :)

Markpyro
08-20-2006, 12:52 PM
Nevermind, found a way around my problem :P

http://pyrom.net/sigs/manual/hr.png

http://pyrom.net/sigs/manual/sigimage.png
*http://pyrom.net/test/blamecountimage.php*http://pyrom.net/test/lastblameimage.php*
http://pyrom.net/test/blameclick.png (http://pyrom.net/test/blame.php)

Jeff
08-20-2006, 8:01 PM
I guess that works :P

Markpyro
08-20-2006, 9:32 PM
It does :), no hassle remembering either. Found a wonderful firefox extension.

http://pyrom.net/sigs/manual/hr.png

http://pyrom.net/sigs/manual/sigimage.png
*http://pyrom.net/test/blamecountimage.php*http://pyrom.net/test/lastblameimage.php*
http://pyrom.net/test/blameclick.png (http://pyrom.net/test/blame.php)

Jeff
08-20-2006, 9:56 PM
It does :), no hassle remembering either. Found a wonderful firefox extension.

What's it called?

Markpyro
08-21-2006, 11:44 AM
Signature. Just that. Simple right click, and it inserts all the text you need. I'm studying how to make the extensions themselves so I can have it automatically insert on every textbox on certain pages, but I'm still working on that :P

http://pyrom.net/sigs/manual/hr.png

http://pyrom.net/sigs/manual/sigimage.png
*http://pyrom.net/test/blamecountimage.php*http://pyrom.net/test/lastblameimage.php*
http://pyrom.net/test/blameclick.png (http://pyrom.net/test/blame.php)

raylu
08-22-2006, 9:25 AM
You can tell a PHP page to send a header that tells the browser it's an image. The rest of the PHP code should be used to display the image.

Or is this not what you wanted at all?

Markpyro
08-22-2006, 10:34 AM
Not at all :/

http://pyrom.net/sigs/manual/hr.png

http://pyrom.net/sigs/manual/sigimage.png
*http://pyrom.net/test/blamecountimage.php*http://pyrom.net/test/lastblameimage.php*
http://pyrom.net/test/blameclick.png (http://pyrom.net/test/blame.php)