0

This is a little complicated to explain but I'll try my hardest, I'm trying to create a tool to edit channel descriptions for TeamSpeak 3, to do this you use a feature called channeledit.

example usage: channeledit channel_description=My\sDescription

Presumably \s = space \n = newline, is there any possible way from using a textarea to php script to have it output the line as:

My\sDescription\nWelcome\sto\smy\sServer

Rather than appearing as: My Description Welcome to my Server

If there is spacing or line breaks, this kills the command and stops it working. Can anyone give me a bit of help here?

Code for this is:

$name = "Test Test Test test test";

$ts3_VirtualServer->execute("channeledit cid=" . $current_cid . " channel_description=" . $name);

Patrick
  • 45
  • 7
  • After testing it's handling spaces fine, just new lines cause it to break.. not sure why though. – Patrick Apr 26 '16 at 18:14
  • Please try: `$name = str_replace("\r","\\n",$name);` – Hexchaimen Apr 26 '16 at 18:35
  • It errors with: test\n test – Patrick Apr 26 '16 at 18:37
  • So the teamspeak 3 framework probably does not want to handle the \ have you just tried passing `urlencode($name)` to it?? – Hexchaimen Apr 26 '16 at 18:38
  • urlencode makes it appear like: Testing+Space%0D%0ANew+Line in the channel, it sets the description do to the fact it creates a full line with now spaces – Patrick Apr 26 '16 at 18:40
  • one more thing I would try, is just changing the standard RC with a NL, like : `$name = str_replace("\r","\n",$name);` If that does not work, go visit the github for the TS3 framework, and see how `channeledit` is handling the string. – Hexchaimen Apr 26 '16 at 18:42
  • 1
    aha! I seem to have gotten it working by doing this: $name = urlencode($name); $name = str_replace("+","\s",$name); $name = str_replace("%0D%0A",'\n',$name); $name = urldecode($name); – Patrick Apr 26 '16 at 18:48
  • Thanks for helping me get there! – Patrick Apr 26 '16 at 18:53

3 Answers3

0

$name=STR_replace(" ","/s",$name) $name= str_replace("\n", '\n', $name);

0
$name = "Test Test
Test test test";
(string)$newname = str_replace(' ', '\\s', $name);
$newname = urldecode(str_replace('%0A', "\\n", urlencode($newname)));

You need to escape (\) the backslash (\). %0A 's are easier to find. My output:

Test\sTest\nTest\stest\stest

bt3of4
  • 36
  • 6
  • For some reason it doesn't seem to like the new lines: Test \n\sTestTest\stest\stest – Patrick Apr 26 '16 at 18:30
  • With hardcoding the value to test test etc.. it works, but when input from the text editor it does not work. – Patrick Apr 26 '16 at 18:31
  • That's why I used the urlencode; to change the original \n's to %0A. It took the $_GET data and made sure it was encoded. Let me play with it, be back in a minute or two. – bt3of4 Apr 26 '16 at 18:37
  • Yeah, but for some reason it wont work when I use a new line in the text area from the form on the html page before. – Patrick Apr 26 '16 at 18:39
  • Search for %0D%0A after the encode for you newline substitute. It gets rid of the mysterious space, but my original code still works. Locale probably. To clarify:`urldecode(str_replace('%0D%0A', "\\n", urlencode($newname)));` – bt3of4 Apr 26 '16 at 18:51
0

If you want to replace spaces and carriage returns with literal \n and \s. I would do the following:

$name = urldecode(str_replace("%0D%0A","\\n",str_replace("+","\\s",urlencode($name))));
Hexchaimen
  • 341
  • 2
  • 9