![]() |
Help with stripping value from return string - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Help with stripping value from return string (/showthread.php?tid=50683) |
Help with stripping value from return string - El Forum - 04-04-2012 [eluser]ppwalks[/eluser] Hi all, got a bit of a problem and wondering if anyone knew of a way to tackle this problem, I have a search field to search specific data compiled of {letters - numbers - letters}, what i need to do is trim of the letters after the numbers, each record has a different string length which is why i cant just remove after a certain amount of characters. Anyone ever done anything like this before or could point me in the right direction, thanks all Paul Help with stripping value from return string - El Forum - 04-04-2012 [eluser]johnpeace[/eluser] That'll be a regular expression...which I suck at...but which there are plenty of people who love to show off their regexp skills...wait for it. Help with stripping value from return string - El Forum - 04-04-2012 [eluser]CroNiX[/eluser] Is there a dash separating the 3 segments (letters-numbers-letters)? If so you could just explode() on the dash and only use the first 2 parts of the resulting array (letters-numbers) Code: $parts = explode('-', $the_string); Help with stripping value from return string - El Forum - 04-04-2012 [eluser]kb1ibh[/eluser] if there is no dash, and the solution above doesnt work, could you post some examples of these letter-number-letter combinations? Edited to Add: if there are no dashes, This might work... Havent had a chance to test it, but i dont think i made any serious errors Code: $string = YOUR_LETTER_NUMBER_LETTER_STRING; It should work with both A1A and AAAAAA11111111AAAAAAAA, no matter how long the string is Help with stripping value from return string - El Forum - 04-05-2012 [eluser]ppwalks[/eluser] thanks guys for the return messages, there are no dashes I demonstrated that to show the 3 seperate values, the values i'm using to search through are postal codes, in the database it has the postcodes as example: cg12 or b1 or can be b12 which is a different area completely so if I match the first letters and numbers it brings back the correct results. hope that makes sense. thanks Paul Help with stripping value from return string - El Forum - 04-05-2012 [eluser]ppwalks[/eluser] Unless there is an sql statement to do the same job also? Help with stripping value from return string - El Forum - 04-05-2012 [eluser]ppwalks[/eluser] No doesn't work it takes first 3 characters |