Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

(help)Php Convert to String

callepogi

The Devotee
Advanced Member
Messages
353
Reaction score
1
Points
38
Royal Wisdom
--eto ung code

<?php

$intVal = 1812ba;
$strVal = ("$intVal");

echo $strVal

?>

Gusto ko sana iconvert sa string completely pabigay naman po ng idea hehe
newbie pa ako sa php :)
 
$intVal = '1812ba';
echo $intVal;

salamat sa reply bale ung "$intVal=1812ba" eto talaga ung result nya walang " ' ' " ganyan na text,,
pano po sya iconvert as string kase na integer yan sya.
 
actually, kapag
Code:
$intVal = 1812ba; // ito ay error - Parse error: syntax error, unexpected 'ba' (T_STRING) kaya imposibleng magkaroon ng result yan, since wala ka '' at magkahalo ang integer (1812) at string (ba)

ang tanong jan, saan ba galing yung 1812ba mo? from a table (database)? or user-defined (variable)? Nilagyan ko ng '' to define na yung value ay string kaya kapag:

Code:
$intVal = '1812ba'; // ito ay magre-result as string
 
Code:
$int = 1812ba;
$intVal = (string)$int;
 
Last edited:
Code:
$int = 1812ba;
$intVal = (string)$int;

Try mo ito. Type casting.
Pero di ko gets bakit mo gustong gawing string yan?
Flexible kasi ang variable ng PHP.

Sabi nga sa php.net
PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.
 
Code:
$var = '1812ba';
echo $var;
Output: 1812ba

Automatic sa php na magiging string yan kapag nag-declare ka ng quoted variable, kahit alphanumeric or special characters pa 'yan. Pwdede mo rin gamitin yung same quote mark na ginamit mo as wrapper ng string value.
Code:
$var = '1812\'ba'


Output: 1812'ba

Kahit puro number characters magiging string pa rin basta i-declare mo lang ng naka-enclose sa quote marks. Pag magdedeclare ka ng integer value sa php, hindi naka-enclose ang numeric value.
Code:
$var1 = '1812'; // This is a string.
$var2 = 1812; // This is an integer.

Flexible ang PHP, kaya pwede mo i-manipulate ang integer na parang string (e.g. echo, concatenate with text as part of the string) at nagbe-behave rin ang string na katulad ng integer (i.e. value = 1/true, or value = 0/false if the string is empty).
 
Last edited:
Thanks po sa mga reply nyo string pala talaga lumabas as output nya i thought na decimals or integers kase di sya na didisplay sa browser pero sa sa console ok sya,, btw naka UBUNTU 16.04 po ung os ko ung project ko po is Serialport communication php base ,, bakit po di sya lumalabas sa browser ung output nya? pero pag sa terminal lumalabas sya..
 
Thanks po sa mga reply nyo string pala talaga lumabas as output nya i thought na decimals or integers kase di sya na didisplay sa browser pero sa sa console ok sya,, btw naka UBUNTU 16.04 po ung os ko ung project ko po is Serialport communication php base ,, bakit po di sya lumalabas sa browser ung output nya? pero pag sa terminal lumalabas sya..

Kung kailangan mo i-display ang value, either echo/print ang gamitin mo. Pwede mo i echo/print pareho kahit integer or string ang variable.
Code:
$var1 = '1812'; // This is a string.
$var2 = 1812; // This is an integer.

echo $var1;
print( $var1 );
 
Back
Top Bottom