Jump to content


Photo

Create a PHP page


  • Please log in to reply
21 replies to this topic

#1 rbiss

rbiss

    Mushroom Tea Party

  • +Clients
  • 1,413 posts

Posted 01 July 2012 - 09:47 AM

I wish there was a page format where you could copy in regular PHP (not raw PHP). I've screwed around with some PHP code on here for a few years now without success, which forced me to bring in drupal as a homepage. My life is only so long andI can't just screw around for all of it trying to make code work. Would be nice to have IP Content more user friendly for PHP.

#2 bfarber

bfarber

    RBT-KS

  • IPS Management
  • 28,575 posts

Posted 02 July 2012 - 08:42 AM

I'm not clear what you mean. You can use "regular" PHP in the "raw" PHP pages (there's no difference).

It's simply that the PHP code you enter is eval'd, so typically you have to omit the open <?php tags. Otherwise, we've created many PHP pages on our main website and in various places on the company forums here (most of them are just quick staff things, not public pages).

Brandon Farber
Development Manager / Senior Support

If it sounds like fun, it's not allowed on the bus!

php5_zce_logo_new.gif     

Invision Power Services, Inc.


#3 CrossFire-Radio

CrossFire-Radio

    Spam Happy

  • +Clients
  • 739 posts

Posted 02 July 2012 - 01:25 PM

I am actually trying to work on a php page, but I am getting confused with what to actually put in... For example:

<?
$array = array('something here', 'Something here', 'Something here', 'Something here',);

$randkey = array_rand($array);

?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<title><?php echo $array[$randkey]; ?></title>

Now when I do that, I get the following error:

[b]Parse error[/b]: syntax error, unexpected '<' in [b]/applications_addon/ips/ccs/sources/pages.php(167) : eval()'d code[/b] on line [b]1[/b]

So how do I actually input the php tag for it to work correctly ?

CrossFire-Radio
DJ Fire - CEO
http://www.crossfire-radio.com
My Downloads

Help


#4 rbiss

rbiss

    Mushroom Tea Party

  • +Clients
  • 1,413 posts

Posted 02 July 2012 - 05:18 PM

I think you'll need to do something like:

$array = array('something here', 'Something here', 'Something here', 'Something here',);

$randkey = array_rand($array);



print "$array[$randkey]";

#5 rbiss

rbiss

    Mushroom Tea Party

  • +Clients
  • 1,413 posts

Posted 02 July 2012 - 05:31 PM



I'm not clear what you mean. You can use "regular" PHP in the "raw" PHP pages (there's no difference).

It's simply that the PHP code you enter is eval'd, so typically you have to omit the open <?php tags. Otherwise, we've created many PHP pages on our main website and in various places on the company forums here (most of them are just quick staff things, not public pages).


There's a big difference to me the end user. On a regular PHP page I can use double quotes nearly anywhere. I can use dynamic javascript snippets etc. I literally had to go with Drupal for off forum site content rather than IP Content after trying off and on for a couple of years to get important php scripts to work. They are the biggest draw to my site.The PHP files could simply be cut and paste into Drupal and work instantly.

It would be great if there could be a selection (HTML, Raw PHP and ______ ) where the source code within that container worked like any other file that can be uploaded via FTP. Save them as html or php extensions etc.


#6 CrossFire-Radio

CrossFire-Radio

    Spam Happy

  • +Clients
  • 739 posts

Posted 02 July 2012 - 10:50 PM

Hmm.. im still getting errors from it, because im using "Raw php" and I have some regular HTML in it... Its spitting out errors because of the HTML..

Is there a way to use both HTML and PHP together on the content page with out getting the errors?

Is it basically using alot of "echo" statements and such in order for it to work correctly?

CrossFire-Radio
DJ Fire - CEO
http://www.crossfire-radio.com
My Downloads

Help


#7 rbiss

rbiss

    Mushroom Tea Party

  • +Clients
  • 1,413 posts

Posted 02 July 2012 - 11:11 PM

I use - print " html in here ";

I haven't had success with echo so I use print.

#8 bfarber

bfarber

    RBT-KS

  • IPS Management
  • 28,575 posts

Posted 03 July 2012 - 08:34 AM

echo and print are near identical and should work the same.

I would convert your PHP code as so:

$array = array('something here', 'Something here', 'Something here', 'Something here',);

$randkey = array_rand($array);

print <<<EOF

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<title>{$array[$randkey]}</title>
EOF;

Alternatively, you can use what you provided almost as is, however you have to remember as I said that it is being eval'd, and thus you need to change the php opening/closing tags to account for this. Here's an example that would probably work.

$array = array('something here', 'Something here', 'Something here', 'Something here',);

$randkey = array_rand($array);

?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<title><?php echo $array[$randkey]; ?></title>
<?php

While I didn't test it, you'll note that because it is being eval'd and the <?php tag is already open, I removed that at the beginning. Next, I let PHP close as you have it so the HTML can print out, BUT then I reopen the <?php tag once it's done so that the rest of the IP.Content code can continue to execute.
  • CrossFire-Radio, IH_Jimbo, Nevo and 1 other like this

Brandon Farber
Development Manager / Senior Support

If it sounds like fun, it's not allowed on the bus!

php5_zce_logo_new.gif     

Invision Power Services, Inc.


#9 CrossFire-Radio

CrossFire-Radio

    Spam Happy

  • +Clients
  • 739 posts

Posted 03 July 2012 - 12:47 PM

Alternatively, you can use what you provided almost as is, however you have to remember as I said that it is being eval'd, and thus you need to change the php opening/closing tags to account for this. Here's an example that would probably work.

$array = array('something here', 'Something here', 'Something here', 'Something here',);

$randkey = array_rand($array);

?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<title><?php echo $array[$randkey]; ?></title>
<?php

While I didn't test it, you'll note that because it is being eval'd and the <?php tag is already open, I removed that at the beginning. Next, I let PHP close as you have it so the HTML can print out, BUT then I reopen the <?php tag once it's done so that the rest of the IP.Content code can continue to execute.


I did the testing on this, and it works perfectly... Thanks so much Brandon

CrossFire-Radio
DJ Fire - CEO
http://www.crossfire-radio.com
My Downloads

Help


#10 Axel Wers

Axel Wers

    Senatus Populusque Romanus

  • +Clients
  • 3,743 posts

Posted 02 August 2012 - 03:01 AM

I am probably dumb, but what is wrong on this?

I created raw php page, to content wrote


<?php
  echo 'Hello World';
  ?>

but I see nothing. What's wrong?

FreeSpace - FreeSpace Forum - Twitter - Facebook - WebMiesto
 
Axel Wers, on 28 Nov 2012 - 7:22 PM, said:
iArcade should be regular app in IP.Suite. Currently IPB looks much more social network than common forum. And games are very popular in social networks.


#11 Marcher Technologies

Marcher Technologies

    $life=FALSE;$code=TRUE;$time--;

  • +Clients
  • 11,717 posts

Posted 02 August 2012 - 03:06 AM

I am probably dumb, but what is wrong on this?

I created raw php page, to content wrote


<?php
echo 'Hello World';
?>

but I see nothing. What's wrong?

echo 'Hello World';
the php tags :rofl:

#12 Axel Wers

Axel Wers

    Senatus Populusque Romanus

  • +Clients
  • 3,743 posts

Posted 02 August 2012 - 05:39 AM

Thanks, It was perhaps issue with Beta 1 edition of IP.Content. I put code to page and it seems that working.

Only big issue when I put php raw code to block

FreeSpace - FreeSpace Forum - Twitter - Facebook - WebMiesto
 
Axel Wers, on 28 Nov 2012 - 7:22 PM, said:
iArcade should be regular app in IP.Suite. Currently IPB looks much more social network than common forum. And games are very popular in social networks.


#13 Grumpy

Grumpy

    Spam Happy

  • +Clients
  • 678 posts

Posted 03 August 2012 - 11:29 PM

To clarify why the tags are an issue,

The scripts you put in as "raw php" is run through eval. As such, the tags cannot be evaluated. It's like writing...

<?php
<?php
echo "hello";
?>
?>

So, you just write no tags.
  • Axel Wers and Kirito like this

#14 Nguyen Duy Quy

Nguyen Duy Quy

    IPB Newbie

  • +Clients
  • 13 posts

Posted 03 April 2014 - 10:02 AM

Please help me, what's wrong in this below code:
 
 
$this->DB->query( "SELECT * FROM forums WHERE 1=1" );
        while( $r = $this->DB->fetch() )
        {
            $row[] = $r;
        }
        
         foreach($row as $r){
 
?>
 
<p><?php echo $r['id']; ?></p>
 
<?php  }
 
 


#15 steve00

steve00

    Needs Serious Help

  • +Clients
  • 2,799 posts

Posted 03 April 2014 - 10:31 AM

as I understand it (I am no coder) you do not use the <?php or ?>(as has been stated a few times above)

 

just use echo $r['id'];


  • Nguyen Duy Quy likes this

==================================================================================

 

If you like my answer or it solves your question then please mark my reply as 'Like' or 'Best Answer' 
 
==================================================================================

 

Video Tutorials: Change Primary Nav Links - Import 3.4.x skin

 

 

World Clock Hook - Member's local time, and time in up to 6 cities around the world

 

 
Having trouble upgrading your skins, we can upgrade your IPB skins for you - PM me for further info.
 
My IPB 3.4.6 Skins: NEW Cobolt - Cerulean - ChritmasTime - Christmas - NOTE: ALL OUR 3.4.5 Skins work with 3.4.6 & require no changes
 
My IPB 3.4.5 Skins: GreenTheme - BlueSwirl - BlueWaveBlueToneRed Theme - RedBase - Red Glass - BluZone - AmplifiedBlue 
 
My IPB 3.4.4 Skins: RedBase - Red Glass - BluZone - AmplifiedBlue 
 
My IPB 3.4.3 Skins: RedBase - Red Glass - BluZone
 
My IPB 3.4.2 Skins: RedBase
 
My IPB 3.4.1 Skins (ONLY $10 EACH): Red GlassGoldenTheme - Scarletise - Purple Grain - GrimsonGrey - ViridisAureus - Red Devil - Carbonise
 
My IPB 3.3.4 Skins: Carbonise - Purple Grain - Blue Grain - Scarletise - CrimsonGrey - Red Devil - ViridisAureus


#16 Nguyen Duy Quy

Nguyen Duy Quy

    IPB Newbie

  • +Clients
  • 13 posts

Posted 03 April 2014 - 11:17 AM

as I understand it (I am no coder) you do not use the <?php or ?>(as has been stated a few times above)

 

just use echo $r['id'];

I have followed the guidance of RBT-KS in the comments



#17 steve00

steve00

    Needs Serious Help

  • +Clients
  • 2,799 posts

Posted 03 April 2014 - 11:41 AM

I have followed the guidance of RBT-KS in the comments

 

but you posted code asking what is wrong and it shows you using <?php and ?> in your code a couple of times so assuming you are trying to use it when you cannot


==================================================================================

 

If you like my answer or it solves your question then please mark my reply as 'Like' or 'Best Answer' 
 
==================================================================================

 

Video Tutorials: Change Primary Nav Links - Import 3.4.x skin

 

 

World Clock Hook - Member's local time, and time in up to 6 cities around the world

 

 
Having trouble upgrading your skins, we can upgrade your IPB skins for you - PM me for further info.
 
My IPB 3.4.6 Skins: NEW Cobolt - Cerulean - ChritmasTime - Christmas - NOTE: ALL OUR 3.4.5 Skins work with 3.4.6 & require no changes
 
My IPB 3.4.5 Skins: GreenTheme - BlueSwirl - BlueWaveBlueToneRed Theme - RedBase - Red Glass - BluZone - AmplifiedBlue 
 
My IPB 3.4.4 Skins: RedBase - Red Glass - BluZone - AmplifiedBlue 
 
My IPB 3.4.3 Skins: RedBase - Red Glass - BluZone
 
My IPB 3.4.2 Skins: RedBase
 
My IPB 3.4.1 Skins (ONLY $10 EACH): Red GlassGoldenTheme - Scarletise - Purple Grain - GrimsonGrey - ViridisAureus - Red Devil - Carbonise
 
My IPB 3.3.4 Skins: Carbonise - Purple Grain - Blue Grain - Scarletise - CrimsonGrey - Red Devil - ViridisAureus


#18 Nguyen Duy Quy

Nguyen Duy Quy

    IPB Newbie

  • +Clients
  • 13 posts

Posted 03 April 2014 - 12:11 PM

 

but you posted code asking what is wrong and it shows you using <?php and ?> in your code a couple of times so assuming you are trying to use it when you cannot

Sorry, I try create block template get forums in IP Content. When write code and save, IP Board Message error as below image:

I user IP Board 3.4.6

 

Attached File  Loi_IPContent.jpg   45.46KB   0 downloads



#19 Nguyen Duy Quy

Nguyen Duy Quy

    IPB Newbie

  • +Clients
  • 13 posts

Posted 04 April 2014 - 08:47 AM

Sorry, I try create block template get forums in IP Content. When write code and save, IP Board Message error as below image:

I user IP Board 3.4.6

 

attachicon.gifLoi_IPContent.jpg

Please help me, thank so much!



#20 bfarber

bfarber

    RBT-KS

  • IPS Management
  • 28,575 posts

Posted 04 April 2014 - 09:13 AM

This seems like a contrived example...for instance, the forums are already loaded into memory so you don't need to run another database query to get them, and your where clause (1=1) is unnecessary.

 

But...I'd probably do it this way if I was you

$this->DB->query( "SELECT * FROM forums" );
while( $r = $this->DB->fetch() )
{
    print "<p>{$r['id']}</p>";
}

Brandon Farber
Development Manager / Senior Support

If it sounds like fun, it's not allowed on the bus!

php5_zce_logo_new.gif     

Invision Power Services, Inc.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users