Php not working?

software development

#1
<?php echo "hello world"; ?>

It gives me an error before world, asking for a ;
(I see this error on FF Javascript console)

What’s happening?
(I’m testing it on a subdomain with php5, and that piece of code is called from another page with a

any idea?

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#2

there may be some php codes before this line. and you miss “;” among those codes.

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color]. Sign Up NOW


#3

Well…those two are my 2 files I’m using for this test. As you can see they are correct…or maybe they should be. :slight_smile:
The console says the problem is between hello and word in the second file. How can you explain that?
------file a.php-----

<?php echo "a"; ?>


b

—file mylist.php—

<?php
echo “hello world”;
?>

The result I see is
a
b
and an error on the console

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#4

it seems you want to include a php file.

try this code: $require(“mylist.php”); or $require_once(“mylist.php”);

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color]. Sign Up NOW


#5

Well no. I want to call some code from another domain/server/whatever
I need to do that way, in order to allow people to call my code without having to change the code but just putting a into it…or some other kind of object…
just imagine an object for wordpress…

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#6

$require and $require_once will call/load the codes from the file to current page. I think that is the one you are looking for.

Save [color=#CC0000]$97[/color] (max discount) on dreamhost plans by using promo code: [color=#CC0000]97CRAZY[/color]. Sign Up NOW


#7

Well, no.

How can I ask you to do that on your wordpress blog, for example?
I should be able to add it with I saw something online, but unfortunately I forgot the link and I dont’ know how to find it again with google :slight_smile:

What do you do if I can’t use php? The solution is a

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#8

As I understand it, is for client-side scripts, such as javascript, that the browser has to interpret. However, PHP is a server-side script, that is to say it is interpreted by the web-server, the browser never gets to see the source, only the results.

Mark


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)


#9

Yes, but you are missing the trick.

on my previous code, you can have:

and then put on the script file:

<?php echo "alert('hi');" ?>

of course that’s not what I wanted to do, but you can see that this is a way to make it easier to include results from other people work on your pages.

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#10

OK, now I see what you are trying to do, but I am still not sure why you are trying to do it. :wink:

Try this…

in a.php

[color=#0000CC][/color]

in mylist.php

[color=#0000CC]<?php
Header(“content-type: application/x-javascript”);
echo “alert(‘hi’);”;
?>[/color]

Mark


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)


#11

it works…I tried something similar without the header stuff,tough.
Anyway, I’d like to get text so alert() is not the solution…
I think the only one I see is to have a

inside a.php and then div.innerHtml = <?php …
inside mylist.php.

The reason is very simple. I can use my “mylist.php” in any kind of page, html,php,asp,whatever…
and I can give you the url so you can use mylist on your website too :slight_smile:

Cupons:[color=#0000CC]MAO_HALFPRICE[/color] : pay only half of the price (L1 plans only) MAO97 get 97$ back


#12

The alert() was just an example, you could of-course output just about anything using javascripts document.write(). For example;

[color=#0000CC]<?php
Header(“content-type: application/x-javascript”);
echo “document.write(‘hello world’);”;
?>[/color]

You can also ‘require’ mylist.php in any kind of page, locally at least, with a simple Apache AddHandler directive in your .htaccess file, but go with whatever method works best for you. :slight_smile:

Edit: I do think the ‘PHP -> Javascript -> Text’ way of doing things is terribly inefficient.

Mark


Save [color=#CC0000]$50[/color] on DreamHost plans using [color=#CC0000]PRICESLASH[/color] promo code (Click for DreamHost promo code details)