Jump to content

[SOLVED] PHP, TXT File Read


jkewlo

Recommended Posts

Well, I got it to work

 

<?PHP

$Data=file_get_contents('idnum2itemdesctable.txt');

$DataArray=explode("\n#",str_replace('\r\n','\n',$Data));
array_pop($DataArray); // Go back one.

$List=ProcessList($DataArray);

/* Process the list! */
function ProcessList($Data)
{
    $List=array();
    if(!is_array($Data))
        return array();
    foreach($Data as $DataItem)
    {
        $FirstPound=strpos($DataItem,'#');
        $Num=intval(substr($DataItem,0,$FirstPound));
        if(is_numeric($Num))
            $List[$Num]=substr($DataItem,$FirstPound+1);

    }
    return $List;
}
?>

 

:) thanks so that problem is solved, So how will I go about doing a str_replace to replace ^777777 with <font color=blue> ???

Link to comment
Share on other sites

:) thanks so that problem is solved, So how will I go about doing a str_replace to replace ^777777 with ???

 

Just the way you said it...  What's the problem?  Have you tried it?

Link to comment
Share on other sites

Ok so I have read the manual and have played around I understand that you have to put it into array() and all is working but It will not replace ^777777 etc.. with <font color=red> etc....

 

This is the code I have to get the Text File information, as you can see I have "ATTEMPTED" to do a str_replace on it :( with little luck

with $Search and $Replace, then I had echoed

 $List = str_replace($Search, $Replace, $List[$row->id]) 

thinking it would work, Still with little luck and have searched google for good examples on str_replace to replace and have tried several other way's as well.

 

I dont really need the <font color> to be there as long as I can get rid of the ^777777 it will be fine.

<?PHP

$Data=file_get_contents('idnum2itemdesctable.txt');

$DataArray=explode("\n#",str_replace('\r\n','\n',$Data));
array_pop($DataArray); // Go back one.

$List=ProcessList($DataArray);

/* Process the list! */
function ProcessList($Data)
{
    $Search = array("^7777777", "^000000", "^000088", "^ffffff");
    $Replace = array("<font color=blue", "<font color=red>", "<font color=purple>", "<font color=white>");
    $List = array();
    if(!is_array($Data))
        return array();
    foreach($Data as $DataItem)
    {
        $FirstPound=strpos($DataItem,'#');
        $Num=intval(substr($DataItem,0,$FirstPound));
        if(is_numeric($Num))
            $List[$Num]=substr($DataItem,$FirstPound+1);

    }
    return $List;
}
?>

Link to comment
Share on other sites

It did not replace anything

 

A potion which cures ^000088Poison^000000, ^000088Silence^000000, ^000088Blind^000000 and ^000088Confusion^000000 effects. ^ffffff_^000000 Weight :^777777 7^000000

Link to comment
Share on other sites

Now if I wanted to remove more then one say ^000088 ^ffffff ^000000 I would make it a array like

$Remove = array('^777777', '^000088', '^000000', '^ffffff');

then in the code I would do.

 

if(is_numeric($Num))
            $List[$Num]=str_replace($Remove,'',substr($DataItem,$FirstPound+1));

 

??

Link to comment
Share on other sites

Possibly, have you tried it?

 

n/m it worked to many characters >

 

 

What?  It wasn't working because you had too many characters?

 

^7777777

supposed to be

^777777

 

>

 

Gotcha, that's what I thought, your wording threw me off.

Link to comment
Share on other sites

Ok, Well I guess I was putting the array in the wrong area, but anyways Problem Solved, I know I have been annoying, and normally I don't ask this many questions but I would Like to thank everyone who have posted here to help me solve my problems >.<

 

A beer Round on me ><

Link to comment
Share on other sites

Ok, Well I guess I was putting the array in the wrong area, but anyways Problem Solved, I know I have been annoying, and normally I don't ask this many questions but I would Like to thank everyone who have posted here to help me solve my problems >.

 

A beer Round on me >

 

It's not that, it's the fact that you post something and ask if it will work.  Instead you should try it out and tell us what the errors are, what happens, what's supposed to happen, etc...

 

A beer Round on me >

 

Ooo, Chimay for me.  :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.