jkewlo Posted May 21, 2009 Author Share Posted May 21, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839245 Share on other sites More sharing options...
Maq Posted May 21, 2009 Share Posted May 21, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839264 Share on other sites More sharing options...
jkewlo Posted May 21, 2009 Author Share Posted May 21, 2009 yes I have tried, It wont display any of the description and I dont want another 7823478 day head ache >< I tried $List = str_replace("^777777", "<font color=blue">); but no luck Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839280 Share on other sites More sharing options...
Maq Posted May 21, 2009 Share Posted May 21, 2009 Maybe you should try reading the manual - str_replace. Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839290 Share on other sites More sharing options...
jkewlo Posted May 21, 2009 Author Share Posted May 21, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839445 Share on other sites More sharing options...
MadTechie Posted May 21, 2009 Share Posted May 21, 2009 if(is_numeric($Num)) $List[$Num]=substr($DataItem,$FirstPound+1); to if(is_numeric($Num)) $List[$Num]=str_replace('^7777777','',substr($DataItem,$FirstPound+1)); Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839488 Share on other sites More sharing options...
jkewlo Posted May 22, 2009 Author Share Posted May 22, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839604 Share on other sites More sharing options...
jkewlo Posted May 22, 2009 Author Share Posted May 22, 2009 n/m it worked to many characters >< Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839610 Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 n/m it worked to many characters > What? It wasn't working because you had too many characters? Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839613 Share on other sites More sharing options...
jkewlo Posted May 22, 2009 Author Share Posted May 22, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839616 Share on other sites More sharing options...
jkewlo Posted May 22, 2009 Author Share Posted May 22, 2009 n/m it worked to many characters >< What? It wasn't working because you had too many characters? ^7777777 supposed to be ^777777 >< Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839617 Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839619 Share on other sites More sharing options...
jkewlo Posted May 22, 2009 Author Share Posted May 22, 2009 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 https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839620 Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 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. Link to comment https://forums.phpfreaks.com/topic/158423-solved-php-txt-file-read/page/2/#findComment-839638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.