9three Posted December 5, 2009 Share Posted December 5, 2009 Hey, I'm trying to figure out how to match first and last name. Example: Jason Fernandez I would like [0]=> Jason [1]=> Fernandez I've failed to do so. :-\ Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2009 Share Posted December 5, 2009 why not just use explode(); http://php.net/manual/en/function.explode.php Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted December 5, 2009 Share Posted December 5, 2009 If the name is a string by itself, I agree with rajivgon's solution (using explode). As usual, there are numerous ways to skin a cat. Another alternative (of perhaps plenty of possibilities) could be to make use of say sscanf: $str = 'Jason Fernandez'; sscanf($str, "%s %s", $firstName, $lastName); echo "$firstName<br />\n$lastName"; In either case, for problem solving things like this, regex would not be what I'd use. Quote Link to comment Share on other sites More sharing options...
9three Posted December 5, 2009 Author Share Posted December 5, 2009 aahh... Why didn't I think about that? ty EDIT: I really like the sscanf function. It's easier to assign variables to it instead of using explode and doing something like $firstName = $arrName[0]; $lastName = $arrName[1]; Quote Link to comment Share on other sites More sharing options...
salathe Posted December 5, 2009 Share Posted December 5, 2009 I really like the sscanf function. It's easier to assign variables to it instead of using explode and doing something like $firstName = $arrName[0]; $lastName = $arrName[1]; What's wrong with: list($firstName, $lastName) = explode(…); Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted December 5, 2009 Share Posted December 5, 2009 What's wrong with: list($firstName, $lastName) = explode(…); I suspect the list functionality is something the OP isn't aware of? Yet another example of how things can be done. [ot]Sometimes I feel like programming is comparable to a buffet. Plenty of options, walk away feeling satisfied.[/ot] Quote Link to comment Share on other sites More sharing options...
cags Posted December 5, 2009 Share Posted December 5, 2009 [ot]Sometimes I feel like programming is comparable to a buffet. Plenty of options, walk away feeling satisfied.[/ot] [ot]But there's always something that leaves you slightly dissapointed.[/ot] Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted December 5, 2009 Share Posted December 5, 2009 [ot]But there's always something that leaves you slightly dissapointed.[/ot] I suppose that depends on which buffet you go to. Quote Link to comment Share on other sites More sharing options...
salathe Posted December 5, 2009 Share Posted December 5, 2009 [ot]Is there any way not to mung the post's HTML when someone pastes a print_r output without code tags? It seems to happen fairly often resulting in problem <ul>s. "Remind the OP to use code tags" is of course an option too. [/ot] Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted December 5, 2009 Share Posted December 5, 2009 [ot]Is there any way not to mung the post's HTML when someone pastes a print_r output without code tags? It seems to happen fairly often resulting in problem <ul>s. "Remind the OP to use code tags" is of course an option too. [/ot] I'm not sure if this is related to disabling WYSIWYG or not.. but perhaps trying that. From top menu, Click profile, then in drop-down sub menu, Modify Profile > Look and Layout - within Look and Layout, ensure "Show WYSIWYG on post page by default is unchecked. If this doesn't do it, then I'm unsure what the solution is to be honest. Quote Link to comment Share on other sites More sharing options...
salathe Posted December 5, 2009 Share Posted December 5, 2009 [ot]It's not when editing, the problem is how post text is parsed when viewing posts/topics. SMF is parsing print_r text (Array( [0] => ... [1] => ... )) like in the first post of this thread. I know everyone should be using code tags, and that we all know what the poster means when things get "broken" like that, but surely** it can't be difficult to persuade SMF to only parse tags like that when wrapped with the appropriate wrapping tags ([ul] or whatever) or ignore them if preceded by the particular sequence of characters in a print_r value. I don't know, maybe that's too much hard work and we just just yell at people to use code tags and/or ignore the problem. ** Famous last words.[/ot] Quote Link to comment 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.