str_pad 함수에서 공백이 먹질 않습니다 ㅠㅠ 정보
str_pad 함수에서 공백이 먹질 않습니다 ㅠㅠ본문
아래 예제문을 보면서 따라하는데요....
http://kr2.php.net/manual/en/function.str-pad.php
<?php
$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"
?>
실제 소스에서
$input = "(";
$strlen_blank = str_pad($input, 22).')';
이렇게 구성하고 $strlen_blank 값을 출력하면 공백이 나오질 않네요...
$input 다음에오는 숫자에 상관없이 ( ) 이렇게 계속 나옵니다.
공백이 먹지 않는 이유가 있을까용 ㅠㅠ
예제대로
$input = "(";
echo str_pad($input, 22);
echo ')';
이렇게 해도 공백이 먹질 않네요. ㅡㅡ 제가 크게 착각하는게 있는지요?
http://kr2.php.net/manual/en/function.str-pad.php
<?php
$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"
?>
실제 소스에서
$input = "(";
$strlen_blank = str_pad($input, 22).')';
이렇게 구성하고 $strlen_blank 값을 출력하면 공백이 나오질 않네요...
$input 다음에오는 숫자에 상관없이 ( ) 이렇게 계속 나옵니다.
공백이 먹지 않는 이유가 있을까용 ㅠㅠ
예제대로
$input = "(";
echo str_pad($input, 22);
echo ')';
이렇게 해도 공백이 먹질 않네요. ㅡㅡ 제가 크게 착각하는게 있는지요?
댓글 전체
해결했습니다 아래 예문으로요...
$string = 'test';
$string = str_pad($string, 10, " ", STR_PAD_BOTH);
// $string now equals ' test'
$string = str_replace(" ", " ", $string);
$string = 'test';
$string = str_pad($string, 10, " ", STR_PAD_BOTH);
// $string now equals ' test'
$string = str_replace(" ", " ", $string);
str_pad는 전체 길이이므로 좌우 똑같은 공백을 나타내어주지 못합니다
$string='testk' 라면 3칸testk2칸 이렇게 되는거죠
이런 경우에는 str_repeat가 좋을 것 같네요
$space=str_repeat(' ',5);
echo $space . $string . $space;
$string='testk' 라면 3칸testk2칸 이렇게 되는거죠
이런 경우에는 str_repeat가 좋을 것 같네요
$space=str_repeat(' ',5);
echo $space . $string . $space;
균이님 감사합니다. 지적하신 문제로 고민하고 있었는데....ㅠㅠ
늘 좋은 조언과 도움에 감사드립니다. (__)
늘 좋은 조언과 도움에 감사드립니다. (__)