Как преобразовать строковую переменную в переменную плавучих / двойнойHtml

Программисты Html
Ответить Пред. темаСлед. тема
Anonymous
 Как преобразовать строковую переменную в переменную плавучих / двойной

Сообщение Anonymous »

Я пытался получить видимую область веб -страницы и передать ее в переменную PHP.
Код сценария, который я использовал: < /p>

Код: Выделить всё



Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)


var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("demo");
x.innerHTML = "Browser width: " + w + ", height: " + h + ".";

< /code>
На веб -странице выводит следующее < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)

Browser width: 1920, height: 892.
< /code>
, который, как я предполагаю, верен, так как он выглядит правильно для разрешения экрана.
Я затем передал переменные в php < /p>
        


< /code>
Результат < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)

Browser width: 1920, height: 892.

$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892
< /code>
Я хочу иметь возможность разрабатывать проценты размера экрана, поэтому я преобразовал строковые переменные в Float /Doubles < /p>
            $DOU_floatwidth = floatval($STR_phpwidth);
$DOU_floatheight = floatval($STR_phpheight);
echo '$DOU_floatwidth is a ' . gettype($DOU_floatwidth) . ' variable, and has a value of ' . $DOU_floatwidth . '
';
echo '$DOU_floatheight is a ' . gettype($DOU_floatheight) . ' variable, and has a value of ' . $DOU_floatheight . '

';
< /code>
и выход теперь < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)

Browser width: 1920, height: 892.

$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892

$DOU_floatwidth is a double variable, and has a value of 0
$DOU_floatheight is a double variable, and has a value of 0
< /code>
Как видите, строка не была передана и преобразована в Float /Double. Я пробовал несколько разных методов, включая $ dou_floatwidth = (float) $ str_phpwidth; 
, а также использование floatval и float на начальной $ str_phpwidth . Если я передаю значения, используя < /p>

Код: Выделить всё

$STR_phpwidth = "1920";
$STR_phpheight = "892";
< /code>
Тогда я ожидаю полный вывод.  < /p>
Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)

Browser width: 1920, height: 892.

$STR_phpwidth is a string variable, and has a value of 1920
$STR_phpheight is a string variable, and has a value of 892

$DOU_floatwidth is a double variable, and has a value of 1920
$DOU_floatheight is a double variable, and has a value of 892

$DOU_onepercent is a double variable
1% of the screen width is 19.2px
< /code>
Полная страница /код: < /p>



Get the size of the current screen/window
The example displays the browser window's height and width: (NOT including toolbars/scrollbars)


var w = window.innerWidth;
var h = window.innerHeight;
var x = document.getElementById("demo");
x.innerHTML = "Browser width: " + w + ", height: " + h + ".";




Есть идеи, где я ошибаюсь?

Подробнее здесь: https://stackoverflow.com/questions/794 ... ble-in-php
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Html»