![]() |
Check part of string is in_array() - 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: Check part of string is in_array() (/showthread.php?tid=8623) |
Check part of string is in_array() - El Forum - 05-24-2008 [eluser]codex[/eluser] Is it possible to check whether if only a part of a string is present in an array? See, i need to check if 'min_length[8]' is in_array, but since the number is variable I can't check the whole string, so I just need to know if 'min_length' is found. Also, I need to return the value between the brackets ([]). Is there a PHP function lets me get 'anything between char [ and char ]'? Or is this requiring regex stuff? Check part of string is in_array() - El Forum - 05-24-2008 [eluser]bradym[/eluser] That's very similar to the validation class in CI - have you looked at system/libraries/Validation.php to see how it's done there? Check part of string is in_array() - El Forum - 05-24-2008 [eluser]codex[/eluser] [quote author="bradym" date="1211698791"]That's very similar to the validation class in CI - have you looked at system/libraries/Validation.php to see how it's done there?[/quote] Indeed, it's the same thing I'm looking for. Should have thought about that. But hey, it's late (well, over here it is) ;-) Thanks again! Edit: Hmm, I spoke too soon. It's not what I need, though it comes in handy in another spot. Basically I need to find 'min_length[anything_here]'. Sorta like a wildcard. Edit2: Come to think about it, it IS what I need. I just looked at it the wrong way. Check part of string is in_array() - El Forum - 05-25-2008 [eluser]codex[/eluser] I thought the function in Validation.php would help with what I'm trying to achieve, but no luck yet. I may be on the wrong track so maybe there's someone else that sees a better solution. I'm creating a module for dynamic form creation. Through the admin you can add and edit inputs of all sorts. The adding/editing also involves settings for validation, which is being written to the db as one string, just as it's done with regular validation settings: required|min_length[2]|alpha_numeric To edit the input values I explode the validation string, check if the rule is in the array, and write the corresponding values to the 'edit'-form on screen: Code: # Any rules found? Check part of string is in_array() - El Forum - 05-25-2008 [eluser]Derek Allard[/eluser] lol, are the voices in your head fighting again? I know exactly how you feel Codex. Check part of string is in_array() - El Forum - 05-25-2008 [eluser]codex[/eluser] [quote author="Derek Allard" date="1211737086"]lol, are the voices in your head fighting again? I know exactly how you feel Codex.[/quote] I'm not sure I understand what you are saying, but do you mean that one moment I say I have it solved and the other moment I haven't? Check part of string is in_array() - El Forum - 05-25-2008 [eluser]Derek Allard[/eluser] Yeah, it was just a joke. In post #2 you seem to have a conversation with yourself. Check part of string is in_array() - El Forum - 05-25-2008 [eluser]codex[/eluser] [quote author="Derek Allard" date="1211737545"]Yeah, it was just a joke. In post #2 you seem to have a conversation with yourself.[/quote] Heheh, yeah ![]() But, what I did in #2, isn't that exactly what those folks at Twitter are doing? Check part of string is in_array() - El Forum - 05-25-2008 [eluser]bradym[/eluser] This may not be the best way to do it, but here's some quick code for you: Code: <? Edit: Looking at your code again, I don't think this is quite what you're looking for.. oops |