This is a discussion on String to array? within the Coding Help forums, part of the Webmaster Help category; I'm currently taking a string from the DB like this ;1|;3|;7| and im changing it to 1 3 7, but ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||||
| I'm currently taking a string from the DB like this ;1|;3|;7| and im changing it to 1 3 7, but the way i'm doing it wont allow for my to use any number above 9 as they are double digits! Is there any way to take a string like 1 4 7 10 and put it into an array and remove the whitespace so in array element 0 i have 1 in array element 1 id have 4 etc? |
| |||||
| if you use split function it should work PHP Code:
__________________ :. Web Design & Development Web Design Ireland :. Search Engines Optimization Search Engines Optimization :. Directory Submission Directory Submission :. News & Press Release Ireland GiveItSocks.com :. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories :. I Have 2 Find It Directory SEF Directory |
| |||||
| Currently i'm using this function call: PHP Code: PHP Code: |
| |||||
| did you try the solution I gave you above? you should leave the "|" so you can use it as a pointer for the split function. |
| ||||
| A split function would do this perfect. Haven't done it in php but I do in asp all the time and it's exactly what you want.
__________________ David Behan Web Design | Mortgages | Memorial Websites | Digital Printing | Golf Holidays Portugal | Conservatories |
| |||||
| Quote:
Thanks. |
| |||||
| As david said ... $data = ";1|;3|;7| "; $array = split('[;|]', $data);
__________________ Forbairt Media | Web Design & Development Galway / Dublin, Ireland - coming soon ... ( vague but descriptive isn't it ) Recent Work: Safari Club African Safari Holidays - Malawi Safaris Other Stuff: FluffyLinkulator Rapid Inclusion Service Tools |
| |||||
| Can't get this to work, any help me??? PHP Code: |
| |||||
| works semi fine for me ... though you are passing in $format to it .. and then defining format in the first line ? |
| |||||
| BTW I should add I don't like what you're doing in your code Code: $format[1] = "PC";
$format[2] = "Xbox";
$format[3] = "Xbox360";
$format[4] = "PS2";
$format[5] = "PS3";
$format[6] = "PSP";
$format[7] = "GC";
$format[8] = "Wii";
$format[9] = "DS";
$format[10] = "GBA";
$formats = ";1|;3|;7|";
$string = "";
preg_match_all("/(\d+)/",$formats,$matches);
$items=$matches[1];
sort($items);
foreach($items as $console)
{
$string .= $format[$console]." ";
}
chop($string);
echo $string;
|
| Tags |
| array, string |
| Thread Tools | |
| Display Modes | |
|
|
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding to a string in PHP???? | ziycon | Coding Help | 5 | 28-09-2007 07:13 PM |
| PHP string infected with weird characters. | littleBird | Coding Help | 5 | 10-03-2007 09:19 AM |
| Can I get a variable name as a string? | montyauto | Coding Help | 5 | 25-02-2007 10:41 PM |
| clean up a string (123..9) | louie | Coding Help | 1 | 11-01-2007 12:58 PM |
| ||||||||
| | ![]() | |||||||