scuarplex Posted September 26, 2010 Share Posted September 26, 2010 Hello, i need to use several ips for an applications and my idea it's to convert them from a text file, to a string and then to an array. My txt would be something like this: 127.0.0.1:21 66.97.171.5:80 192.0.100.1:8080 So now i have the string, and i was thinking to use preg_split() to convert it into an array. My problem is that patterns are a total mystery to me and i have no clue how to make one. I would basically would need a pattern to split the string on every /n Quote Link to comment https://forums.phpfreaks.com/topic/214443-need-help-with-a-pattern/ Share on other sites More sharing options...
Zane Posted September 26, 2010 Share Posted September 26, 2010 If they're already in a txt file, separated by lines, you don't need a pattern Just use the file() function. It returns an array of each line. Quote Link to comment https://forums.phpfreaks.com/topic/214443-need-help-with-a-pattern/#findComment-1115905 Share on other sites More sharing options...
scuarplex Posted September 26, 2010 Author Share Posted September 26, 2010 Solved, thanks Still, if anyone know how to make a pattern for a jump line, post it please. Quote Link to comment https://forums.phpfreaks.com/topic/214443-need-help-with-a-pattern/#findComment-1115920 Share on other sites More sharing options...
.josh Posted September 26, 2010 Share Posted September 26, 2010 ~^.*$~ would be a pattern for a full line. But you really don't need it. Quote Link to comment https://forums.phpfreaks.com/topic/214443-need-help-with-a-pattern/#findComment-1116039 Share on other sites More sharing options...
scuarplex Posted October 1, 2010 Author Share Posted October 1, 2010 Actually i think i need file and the pattern, file() will do the array with the line and with the \n at the end right? Edit: solved with a flag called: "FILE_IGNORE_NEW_LINES". Sorry Quote Link to comment https://forums.phpfreaks.com/topic/214443-need-help-with-a-pattern/#findComment-1117824 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.