Current location: Hot Scripts Forums » Programming Languages » PHP » how to get info from TXT file between %%customTags%% as vars??

how to get info from TXT file between %%customTags%% as vars??

Reply
  #1 (permalink)  
Old 07-23-03, 04:53 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
how to get info from TXT file between %%customTags%% as vars??

How do I get text as a variable contents from a TXT file between
certain "custom tags"?

Here is what I mean. If I have a text file named "info.txt" and it's contents are:
Code:
%%meta1%%
This is some dummy stuff for a tag that I might make
%%meta1%%

%%meta2%%
There can be more than one of the current sets
%%meta2%%

%%tag%%
Some of these tags might not even have the same name
%%tag%%

%%changes%%
And I might make a script to add to more tags to this file or 
re-write it occasionally with new tags/contents
%%changes%%

Then in another PHP file I might want to get things like this:

PHP Code:
<?
$meta 
= array("Some of these tags might not even have the 
same name"
"There can be more than one of the current sets");
    
// or
$meta1 "This is some dummy stuff for a tag that I might make";
    
// or
$tag "Some of these tags might not even have the same name";
   
// etc....
?>
I assume I have to open, then search the TXT file for words that begin after a specified "tag" and end at the same
specified "tag" but I have no idea of the syntax to do that search.

Any help? SHould I be more clear?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-26-03, 05:50 AM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
Try this (assuming the file with the tags in it is tags.txt):

PHP Code:
<?
$lines 
file("tags.txt");

foreach (
$lines as $line){
 if (
preg_match("/%%(\w+)%%/",$line,$match)){
  
$last $match[1];
 }else{
  if (
$last){ ${$last} .= $line; }
 }
}

print 
"Meta1: $meta1<br>\n";
print 
"Meta2: $meta2<br>\n";
print 
"Tag: $tag<br>\n";
print 
"Changes: $changes";
?>
__________________
Chris (aka Skeleton Man)
ProgrammingTalk's Perl/PHP Moderator !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-26-03, 06:00 AM
alesh.ru alesh.ru is offline
Internet-paraSITE
 
Join Date: Jul 2003
Location: Moscow, Russia
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:
<? 
//Author Mitya Aleshkovsky [email]mitya@alesh.ru[/email] 

    
function cut_html($tag,$string){ 
         
        
$tag=str_replace("<","",$tag); 
        
$tag=str_replace(">","",$tag); 

        
preg_match("!<$tag>(.*?)</$tag>!si",$string,$ok); 


        return (
$ok[1]); 
    } 



$str="123 <body>456</body>897"

echo 
cut_html("body",$str); 

?>
__________________
From Russia with love
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 4 11-18-08 07:23 AM
New Web Host, New Problem! justchat PHP 2 09-29-03 03:39 PM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 10:43 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM
get vars from local file into textareas paulj000 PHP 5 07-15-03 02:02 AM


All times are GMT -5. The time now is 04:44 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.