0

I'm extracting usernames from a string starting with # sign and converting to a hashtag link. For this my code is

$str = "#John_Smith  #DanielCarter and #JackFoster are the good programmers";

$regex = "/#+([a-zA-Z0-9@_]+)/";

$string = preg_replace($regex, '<a href="user_page.php?userName=$1">$0</a>', $str);

Now the problem is that the hashtag link on emojis is stopping and not moving further, and I know the code below is used to track the emojis.

(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])

But I don't know how to use in this situation

The Eagle
  • 13
  • 2
  • 1
    Why can't you simply consider everything up to the first white space character as "user name"? – arkascha Oct 31 '22 at 08:12
  • You won't be able to create a full and robust positive list for acceptable characters anyway, considering your definition "some special characters" ... – arkascha Oct 31 '22 at 08:13
  • Because I don't want to consider everything instead of alphabets, emojis, @ and underline(_) . – The Eagle Oct 31 '22 at 08:18
  • is this what you want? https://onecompiler.com/php/3ymjh47p3 – Alive to die - Anant Oct 31 '22 at 08:18
  • You question is the same as "how do you validate usernames?" – shingo Oct 31 '22 at 08:23
  • 1
    If so, then you should be able to name precisely what you actually want to exclude. Because it is not clear from the current description. "Some special characters" does not help (apart from the fact that there is no such thing as a "special characters", they are all just perfectly fine characters ...). Also "alphabets" is difficult considering the sheer amount of characters you probably have to consider being part of that. – arkascha Oct 31 '22 at 08:23
  • No Bother @Anant-Alivetodie I don't want to trim the emojis I want to include all the emojis and further alphabets which are attached to that emoji within the hashtag link, but problem is that the link is stopping on the emoji and not including whole name which is being after the emoji like – The Eagle Oct 31 '22 at 08:47
  • I just want to include whole name like – The Eagle Oct 31 '22 at 08:49
  • Check this answer https://stackoverflow.com/questions/50929396/regex-for-entering-letters-without-emojis , that shows how to handle emojis. – D. Dimopoulos Oct 31 '22 at 09:53

0 Answers0