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> ??? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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; } ?> Quote Link to comment 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)); Quote Link to comment 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 Quote Link to comment 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 >< Quote Link to comment 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? Quote Link to comment 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)); ?? Quote Link to comment 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 >< Quote Link to comment 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. Quote Link to comment 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 >< Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.