Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/197910--/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/197910--/#findComment-1038531
Share on other sites

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 ( " )

Link to comment
https://forums.phpfreaks.com/topic/197910--/#findComment-1038532
Share on other sites

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 :)

Link to comment
https://forums.phpfreaks.com/topic/197910--/#findComment-1038620
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.