Hey
I have some text in a .txt file which using class-textobject (or class-anyfile?) I treat as an image. How do I print the bare contents of this text file?
I tried many functions and only printCustomSizedImage* work, but they don't return bare contents.
I used: ` This returns:This is the content of foo.txt`
I would like pure text returned, nothing else. Is this possible?
You will have to use standard PHP function like file_get_contents() to read and display the plain file. Which is what the plugin uses to get it as well. See the getContent() method of it. You could also use getContent() and strip the wrapping span via strip_tags.
And one more question, is it possible to print just the image filename without anything else? Like getUnprotectedImageURL minus the paths and minus the extension.
Ooh thank you, I got it working! Though I don't know if what I did is either correct or efficient Is this the best way to do it?
``
I managed to get the full path without the extension using `` which returns
/zp/albums/foo/bar/kitteh
Now how do I get rid of "/zp/albums/foo/bar/"?
That one just removes "/zp".
Success!
``
Thank you!
For anyone interested, the pathinfo and stripsuffix functions works great for getting parts of a path or filename!
pathinfo returns an array consisting of dirname, basename and extension.
stripsuffix does as the name implies.
To get the txt filename:
$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = $txtFilename ['basename'];
To strip the suffix:
$txtFilename = stripSuffix($txtFilename);
You could shorten and merge the two:
$txtFilename = pathinfo(getUnprotectedImageURL()); $txtFilename = stripSuffix($txtFilename ['basename']);
I used the code you gave me above for some time, but once things started getting hairy I found this to be quicker to experiment with. Both have uses, hope this helps someone too