11Tami Posted April 11, 2007 Share Posted April 11, 2007 Hello, this works. <?php // current time echo date('h:i:s'); ?> I need to put it inside other php and still get it to execute. Can someone tell me how? This is what I tried but it doesn't show the time, anyone know why? Please let me know, thank you very much. <?php $string = '</?php echo date(\'h:i:s\'); ?>'; echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/ Share on other sites More sharing options...
Glyde Posted April 11, 2007 Share Posted April 11, 2007 <?php $string = "echo date('h:i:s');"; eval($string); ?> Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226513 Share on other sites More sharing options...
jitesh Posted April 11, 2007 Share Posted April 11, 2007 <?php $string = date('h:i:s'); echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226514 Share on other sites More sharing options...
11Tami Posted April 11, 2007 Author Share Posted April 11, 2007 Wow Glyde you found me again. Thank you. I even made it very simple and tried this: <?php $string = '</?php echo "test"; ?>'; echo $string; ?> Doesn't php let you pass one php within another? Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226518 Share on other sites More sharing options...
kenrbnsn Posted April 11, 2007 Share Posted April 11, 2007 What exactly are you trying to do. What you've shown doesn't make any sense. Ken Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226532 Share on other sites More sharing options...
11Tami Posted April 11, 2007 Author Share Posted April 11, 2007 I'm just trying to learn how to put and parse one php code inside another and still get it to work. Once I figure out how to do that I may be doing something else with it later, not sure yet. Here it is again. <?php $string = '</?php echo "test"; ?>'; echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226552 Share on other sites More sharing options...
ryeman98 Posted April 11, 2007 Share Posted April 11, 2007 No no no, make it look like this: <?php $string = "date("h:i:s")"; echo "string"; ?> Or, if you want to display the date you could just do this: <?php $date = date("h:i:s"); echo $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226558 Share on other sites More sharing options...
wildteen88 Posted April 11, 2007 Share Posted April 11, 2007 You cannot put PHP inside PHP. If you have this: <?php $string = '<?php echo "test"; ?>'; echo $string; ?> Then look at Glyde's post. <?php $string = "echo date('h:i:s');"; eval($string); ?> You have to use eval. eval parses PHP code in a string. However if all you want to do is echo the date after a string then do this: echo 'The date to day is: ' . date("D jS F Y"); You use the concatenation (concat for short) operater (.). To tie the string to a function that returns a string. Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-226683 Share on other sites More sharing options...
11Tami Posted April 11, 2007 Author Share Posted April 11, 2007 Thanks wild teen, it helps when someone explains why it is done a certain way. Then I can remember it better and understand it. Quote Link to comment https://forums.phpfreaks.com/topic/46537-how-to-parse-a-small-code/#findComment-227280 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.