I am planning to create a web app and I have a question about how to create a Facebook or Twitter name like "@ Myname "is named
Find them in a string with this regex .... < / P>
$ Str = 'yo @bob, what's up? I have a new email, tell tom@bob.com, @Joyon, @ Alex ;; Preg_match_all ('/ \ s @ (? P & lt; ment & gt; \ w +?) \ B /', $ str, $ is mentioned); Var_dump ($ ment); output array (3) {[0] = & gt; Array (3) {[0] = & gt; String (5) "@bob" [1] = & gt; String (6) "@John" [2] = & gt; String (6) "@ black"} ["ment"] = & gt; Array (3) {[0] = & gt; String (3) "Bob" [1] = & gt; String (4) "John" [2] = & gt; String (4) "Alex"} [1] = & gt; Array (3) {[0] = & gt; String (3) "Bob" [1] = & gt; String (4) "John" [2] = & gt; String (4) "Alex"}} Of course, you can recognize them in real-time JavaScript in a string, just change a regex to javascript.
Then, you will see your database based on the name you tagged, and then do what you need to do!
You can deduct requests by restricting your regex as a valid username, e.g. / \ w {6,} / .
Comments
Post a Comment