jmcall10 Posted April 7, 2010 Share Posted April 7, 2010 Hi, I have a script that is not written by myself and uses "<?" and my server seems to only work when its changed to "<?php" This is fine for most of the script, however there are some sections of code that does not allow for this. For example: <? version <input name="username" type="text" value="<?=$row2["username"]?>" > <?php <input name="username" type="text" value="<?php=$row2["username"]?>" > when I change it to <?php in this case it does not work. I have put in that works but not sure if this is good practice : <input name="username" type="text" value="<?php echo $row2["username"]?>" > Does anyone know why and how I can change it? Quote Link to comment https://forums.phpfreaks.com/topic/197910--/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 7, 2010 Share Posted April 7, 2010 <?php echo is the correct usage. Quote Link to comment https://forums.phpfreaks.com/topic/197910--/#findComment-1038530 Share on other sites More sharing options...
Zane Posted April 7, 2010 Share Posted April 7, 2010 They are called short tags. It's best to leave them off, but one of the percs of having them turned on is that you can use them to perform ONE function (on the fly).... without a semicolon to boot. =function() ?> =echo 'blah' . 'blah' . 'blahblah' ?> I have put in that works but not sure if this is good practice : " > Does anyone know why and how I can change it? You could do a find and replace with your IDE/HTML editor. Find "=" and replace it with "<?php echo " But that's just assuming everything is just an echo... which is what it looks like. Quote Link to comment https://forums.phpfreaks.com/topic/197910--/#findComment-1038531 Share on other sites More sharing options...
Jax2 Posted April 7, 2010 Share Posted April 7, 2010 As the other person said, that IS the correct usage, however, a lot of coders seem to find it cheesy when people break in and out of php a lot ... I do the same thing, myself, and quite often, too, however, it can be re-written without having to break out of php: echo "<input name='username' type='text' value='".$row2["username"]."' > Just another way of writing it, and either echoing out " with \" or simply using single quotes ( ' ) instead of doubles ( " ) Quote Link to comment https://forums.phpfreaks.com/topic/197910--/#findComment-1038532 Share on other sites More sharing options...
jmcall10 Posted April 7, 2010 Author Share Posted April 7, 2010 Thanks guys I went with the echo Quote Link to comment https://forums.phpfreaks.com/topic/197910--/#findComment-1038617 Share on other sites More sharing options...
premiso Posted April 7, 2010 Share Posted April 7, 2010 a lot of coders seem to find it cheesy when people break in and out of php a lot Not really sure about this statement. It is all in context. I tend to only ever use <?php echo $var;?> if the file I am working in is a "template" file that is to display data. So when you call it via include('template.php'); the code gets processed. If I am debugging I tend to do the echo. If I want to display the form built via a php file, non templated, I stored the data in a string and would use the similar setup to the echo except something $display .=. But given what the user posted in the original topic it looks like it is setup as a template of sorts and would use the <?php echo $var; ?> Just clarifying Quote Link to comment https://forums.phpfreaks.com/topic/197910--/#findComment-1038620 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.