andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Filename without .txt on form page

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> MadLibs
View previous topic :: View next topic  
Author Message
brownafroduck
Newbie


Joined: 30 Dec 2003
Posts: 2

PostPosted: Tue Dec 30, 2003 9:17 pm    Post subject: Filename without .txt on form page Reply with quote

How can I show the filename of the textfile that is being used to generate the form... Ok, that was confusing. Basically, I want to have a title on the form when you fill it out (so that it is easier for users to see whether they have already done that Madlib before). I want this title to be derived from the filename of the txt file that is producing the form for the madlib. So you basically strip the .txt part... Yeah, I hope that makes sense.

Please help. Very Happy
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Wed Dec 31, 2003 6:45 am    Post subject: Reply with quote

Hi, and welcome to the board!

When the story is displayed, first it uses the getStory function. This gets the filename, the title of the story and the story details. What you could do is just display the title of the story.... However, it's not _quite_ that easy. You see, it gets the story and then displays the form without any pause, and you want to display the title first. There is a fairly simply solution to it, though, which should work out for you (I haven't tried it, just winging it). Use PHP's built in caching functions; ob_*

For example, try something like this:

PHP:
<?php

    
require 'class.madlibs.php';

    
$ml = new madlibs();
    
$ml->useFS('.''.txt');
    
ob_start();
    
$ml->displayMadlib();
    
$story ob_get_contents();
    
ob_end_clean();
    echo 
'<strong>'$ml->inText['title'], '</strong><br /><br />';
    echo 
$story;

?>


Or if you REALLY wanted to show the filename instead, use $ml->inText['id']. You can set your files not to have an extension, which makes displaying the file name without a '.txt' much easier Smile, but if you want to remove the extension, then try something like this:

PHP:
<?php

$name 
$ml->inText['id'];
echo 
substr($name0, (strrpos($name,".") ? strrpos($name,".") : strlen($name)))

?>


But personally, I would just stick with the story title. Smile

Give it a whirl and let me know if it works.

Regards,

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
brownafroduck
Newbie


Joined: 30 Dec 2003
Posts: 2

PostPosted: Wed Dec 31, 2003 3:27 pm    Post subject: Reply with quote

Thanks so much for your quick repsonse!

I was thinking along the lines of the filename so that the topic of the story wasn't given away.

I am going to try this right now and get back to you!

EDIT:
Displaying the story title works wonderfully, but I cannot figure out how to display just the filename. Unless I am missing something (which could very well be the case), the code that you gave doesn't work. Crying or Very sad Don't worry about it, though, I'll just use the title. The only reason that I don't like displaying the title is because when it displays the completed madlib, it displays it again. Is there a way to work around that? Thank you so much for you time!

Also, is there a way that you can call specific madlibs to appear?
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Thu Jan 01, 2004 11:18 am    Post subject: Reply with quote

brownafroduck wrote:
Displaying the story title works wonderfully, but I cannot figure out how to display just the filename. Unless I am missing something (which could very well be the case), the code that you gave doesn't work.


Didn't see that you had edited this message, else I would have replied sooner. Smile The code does work - just tweaked a little. I've just tried this exact code out, and it worked just fine:

PHP:
<?php

    
require 'class.madlibs.php';

    
$ml = new madlibs();
    
$ml->useFS('./stories''.txt');
    
ob_start();
    
$ml->displayMadlib();
    
$story ob_get_contents();
    
ob_end_clean();
    if (
$_POST['id'] == '')
    {
        
$filename substr($ml->inText['id'], 0, (strrpos($ml->inText['id'],".") ? strrpos($ml->inText['id'],".") : strlen($ml->inText['title'])));
        echo 
'<strong>'$filename'</strong><br />';
    }
    echo 
$story;

?>


Or if you want to still use the title, try this:

PHP:
<?php

    
require 'class.madlibs.php';

    
$ml = new madlibs();
    
$ml->useFS('./stories''.txt');
    
ob_start();
    
$ml->displayMadlib();
    
$story ob_get_contents();
    
ob_end_clean();
    if (
$_POST['id'] == '')
    {
        echo 
'<strong>'$ml->inText['title'], '</strong><br />';
    }
    echo 
$story;

?>


brownafroduck wrote:
Also, is there a way that you can call specific madlibs to appear?


Hmm.. currently no, not really. You could try pre-populating $_POST['id'] with the filename and then starting up the class... that might work. Perhaps I'll update the class at some point so that you can select the story to display. But for now, well.. you'll have to tweak it yourself if you want to do that. Smile

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> MadLibs All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group