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 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. 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. 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. 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 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
Archived
This topic is now archived and is closed to further replies.