lolalola
lolalola

Reputation: 3823

in string spec. symbol, php

how to see in string all spec symbols?

Examples: space, new line, tab and t.t

Upvotes: 0

Views: 210

Answers (2)

KingCrunch
KingCrunch

Reputation: 131931

I dont know exactly, what you mean by "see".

You can use preg_match_all() with the *PREG_OFFSET_CAPTURE* -Flag and you will get any occurence. You can then use this to do, what you like. If you really just want to see "something", use Pekkas solution.

$string = str_replace(array("\t","\n"," "),array('<TAB>','<NEWLINE>','<SPACE>'), $string);

Its exactly the same, but in one call.

Update: addcslashes()

$string = addcslashes($string, "\n\t\r ");

Upvotes: 2

Pekka
Pekka

Reputation: 449515

You can use str_replace() to make the characters of your choice visible:

$string = "Insert here a string that contains spaces, newlines, tabs";

$string = str_replace("\t", "<TAB>", $string);
$string = str_replace("\n", "<NEWLINE>", $string);
$string = str_replace(" ", "<SPACE>", $string);

Upvotes: 1

Related Questions