Help with hashtags, how to replace them

Hi there i am trying to fix this problem, please help

I am trying to use the PPP on down and giving it a script

$user= The ppp username will be something like “hi#there”

:local name “$user”;
{
:local urlstring “$user”
:local urlEncoded

:for i from=0 to=([:len $urlstring] - 1) do={
:local char [:pick $urlstring $i]

:if ($char = “#”) do={
:set $char “%23”
}
:set urlEncoded ($urlEncoded . $char)

}


}
/tool fetch url=“https://website.com/number=$urlEncoded”;

how do i replace the # to %23 so that it can open that website with it showing https://website.com/number=hi%23there

thanks a million for the help

Don’t put the real addresses at random, you piss off the other administrators who are called non-existent pages, and what’s more, it looks like spam.
Always use example.com which is there for that…

Your question is not clear at all,
explain yourself better why you ask for something you already do and you don’t realize it?

{
:local user “micio#miao”

:local hashencode do={
:local constr “” ; :local chr “”
:for pos from=0 to=([:len $1] - 1) do={
:set chr [:pick $1 $pos ($pos + 1)]
:if ($chr = “#”) do={:set chr “%23”}
:set constr “$constr$chr”
}
:return $constr
}

/tool fetch url=“https://example.com/user-online.php\3Fusername=$[$hashencode $user]”
}
The URL called is:
https://example.com/user-online.php?username=micio%23miao"

P.S.: # is “number sign” or “hash”, but not “hashtag”…

hi there sorry for my bad english.

I’ll repeat my questions.

I am currently using PPPOE for my clients and everytime a pppoe client disconnect i want it to hit a link on my website to give it get request so that it can save the data to mysql.
Currently users with # doesnt seem to work

For now users with just text and numbers are fine
example ------
PPPOE on down
:local nama “$user”;
/tool fetch url=“https://example.com/number=$user&bid=BID202202004”;


So the $user is just the username of the pppoe user.

Now i have problems with pppoe usernames such as : SR#kennedy

I need it hit the website like this example
On down
Lets say the user is SR#kennedy
:local nama “$user”;
/tool fetch url=“https://example.com/number= SR%23kennedy &bid=BID202202004”; ← somehow to make it work this way sir

i am new to scripting in mikrotik , could you kindly help me make a script that i can just copy paste into mikrotik. I will be placing this script on ppp>profile>scripts>on down and on up

Thanks a million

hi there please anyone could help me out?
I am currently using PPPOE for my clients and everytime a pppoe client disconnect i want it to hit a link on my website to give it get request so that it can save the data to mysql.
Currently users with # doesnt seem to work

For now users with just text and numbers are fine
example ------
PPPOE on down
:local nama “$user”;
/tool fetch url=“https://example.com/number=$user&bid=BID202202004”;


So the $user is just the username of the pppoe user.

Now i have problems with pppoe usernames such as : SR#kennedy

I need it hit the website like this example
On down
Lets say the user is SR#kennedy
:local nama “$user”;
/tool fetch url=“https://example.com/number=SR%23kennedy &bid=BID202202004”; ← somehow to make it work this way sir

i am new to scripting in mikrotik , could you kindly help me make a script that i can just copy paste into mikrotik. I will be placing this script on ppp>profile>scripts>on down and on up

Thanks a million

The # needs to be URL encoded (e.g. with some chars converted like # converted to %23). You can use a function to do this in your PPPoE script to call fetch.

{
# from http://forum.mikrotik.com/t/replace-characters-in-string-url-encode/76863/11
:local URLENCODE
:set URLENCODE do={
    :local Chars {" "="%20";"!"="%21";"#"="%23";"%"="%25";"&"="%26";"'"="%27";"("="%28";")"="%29";"*"="%2A";"+"="%2B";","="%2C";"/"="%2F";":"="%3A";";"="%3B";"<"="%3C";"="="%3D";">"="%3E";"@"="%40";"["="%5B";"]"="%5D";"^"="%5E";"`"="%60";"{"="%7B";"|"="%7C";"}"="%7D"}
    :set ($Chars->"\07") "%07"
    :set ($Chars->"\0A") "%0A"
    :set ($Chars->"\0D") "%0D"
    :set ($Chars->"\22") "%22"
    :set ($Chars->"\24") "%24"
    :set ($Chars->"\3F") "%3F"
    :set ($Chars->"\5C") "%5C"
    :local URLEncodeStr
    :local Char
    :local EncChar
    :for i from=0 to=([:len $1]-1) do={
        :set Char [:pick $1 $i]
        :set EncChar ($Chars->$Char)
        :if (any $EncChar) do={
            :set URLEncodeStr "$URLEncodeStr$EncChar"
        } else={
            :set URLEncodeStr "$URLEncodeStr$Char"
        }
    }
    :return $URLEncodeStr
}

:local reportingurl "http://example.com/number=$[$URLENCODE $user]&bid=$[$URLENCODE "BID202202004"]"
:local fetchresult [/tool fetch url=$reportingurl output=none as-value]
/log info "send popoe down to SQL via $reportingurl with result: $[:tostr $fetchresult]"
}

Please don’t post a question twice. See http://forum.mikrotik.com/t/help-with-hashtags-how-to-replace-them/167913/4

Merged

How many times?

You sure about url syntax:
https://example.com/number=SR%23kennedy&bid=BID202202004
???
is not like
https://example.com/page?number=SR%23kennedy&bid=BID202202004
???


You already have the solution:
{
:local user “SR#kennedy”

:local hashencode do={
:local constr “” ; :local chr “”
:for pos from=0 to=([:len $1] - 1) do={
:set chr [:pick $1 $pos ($pos + 1)]
:if ($chr = “#”) do={:set chr “%23”}
:set constr “$constr$chr”
}
:return $constr
}

/tool fetch url=“https://example.com/number=$[$hashencode $user]&bid=BID202202004”
}
The URL called is:
https://example.com/number=SR#kennedy&bid=BID202202004"

I have tried placing the code into mikrotik and nothing happend on down, so i tried disconnecting the pppoe user. sorry i dont really know how the scripting system works.
here is the link of the screenshot https://imgur.com/a/kBdRpXh

thank you sir

So you don’t need just a hint, but the whole script… :laughing:
:local uname “” ; :local tmp “”
:for pos from=0 to=([:len $user] - 1) do={
:set tmp [:pick $user $pos ($pos + 1)] ; :if ($tmp = “#”) do={:set tmp “%23”}
:set uname “$uname$tmp”
}

:local URL “https://example.com/number=$uname&bid=BID202202004

:log info “Retrieved URL $URL”

/tool fetch keep-result=no url=$URL