Create a PHP page

22 posts in this topic

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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:


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



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

Share this post


Link to post
Share on other sites

Posted

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]";

Share this post


Link to post
Share on other sites

Posted




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.

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted

I use - print " html in here ";

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

Share this post


Link to post
Share on other sites

Posted

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

I would convert your PHP code as so:

$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;

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












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.

m3rk0rd, Nevo, IH_Jimbo and 1 other like this

Share this post


Link to post
Share on other sites

Posted


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

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted


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:

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Kirito and Axel Wers like this

Share this post


Link to post
Share on other sites

Posted

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 }

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

post-522714-0-59936400-1396545070_thumb.

Share this post


Link to post
Share on other sites

Posted

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!

Share this post


Link to post
Share on other sites

Posted

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>";
}

Share this post


Link to post
Share on other sites

Posted

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>";
}

Thank for your reply.

My problem is need show topic's image to home page IP Content.

I created a template in Block Template with Feed type Forums-> Forums
I got title latest in each topic, but not get the image follow attachments according to.
How to I get first image in each topic to show home page?
Please help me, thank so much!

Share this post


Link to post
Share on other sites

Posted

Please post in the peer help forum if you need assistance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Who's Browsing   0 members

    No registered users viewing this page.