MyBB Community Forums

Full Version: Parsing usernames?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm considering creating a MyBB plugin, however, I am curious as to how I could automatically parse usernames out of a wall of text like


Quote:sodfjh98j423f98njsadfhsa8dhfsahdfoiudsayhfiusahfdiuhgdsfiuhsa798fhwa98hfn7dsahbfudsahbfiuasdgfdjahLee Merrimandfijaw98jhfPOIJD(*jhfdOIHFD98ajngfv98ashgfd98hdsaf8dhasfpdh


I need to pull my name out of that (Will need to work for multiple usernames.) I've thought of one way but it's probably a very bad way to do it, so I'm idea fishing.
Use str_replace or something to look for Lee Merriman and replace it with the parsed username. Not sure exactly what you're trying to accomplish though. Just an idea.
But say it was your username in there instead of mine. Or someone else. All I can think of is some sort of loop to check it against registered usernames, parsing with regex from the minimum username length to the max. But god, that'd be a lot of queries..
can you control the format of the input string?
No. What I'm doing (since it's apparently needed) is parsing MyBB posts for usernames that are registered.
At this point, I'm considering whenever the plugin is called, download a list of the usernames registered, using something to check them against this loop that I'm semi-working on.
its possible, but not resource friendly at all. best bet would be a custom mycode/plugin that would parse at post time and insert a UID for the current username (in case they change later)

just cant apply it to existing posts in a easy way
Not looking to apply it to existing, just new posts. However, if I posted a long wall of text, pavemen, then kept going on, with any sort of characters before and/or after, I'd like to grab your username out of this. But if I added faviouz in here too, now I need to grab both.


TL;DR I'm using [@Username] until I find a better idea
I would force a user to use @ or a mycode if they want to highlight a user and then you can can search for that marker and then get the UID which you can then modify the original mycode to add the UID. then on parsing you can convert the mycode at display time
I've done it with [@username], using LIKE %username% so partial searches work. Should I release the plugin?
but what are you doing about it when the user changes their name? you should find the match at post time, set a mycode like [user=1234]username[/user] then parse teh mycode at display time,
Pages: 1 2