doutongya8378
doutongya8378
2015-09-23 19:26
浏览 201
已采纳

在strtotime()函数以及html结构中使用变量

Sorry for asking this question, but I am very new in php and I am stucked at this issue. I use the code part to read a txt file as below:

I want to read a txt file in php and create an event by using the information coming from the text.

events.txt includes:

SEPTEMBER-21-2015-10am
Google Event
http://www.google.com
That is very enjoyable

...

$fh = fopen('events.txt','r');
$counter = 0;
while ($line = fgets($fh)) {
    if($counter % 4 == 0)
    {
        $eventDate = explode("-",$line);
    }
    if($counter % 4 == 1)
    {
        $eventTitle = $line;
    }
    if($counter % 4 == 2)
    {
        $eventLink = $line;
    }
    if($counter % 4 == 3)
    {
        $eventDesc = $line;
    }
    ++$counter;
}
fclose($fh);

I am able to read my file and assign my data to the related variables. However, I would like to use them to create $event1 like:

$event1 = $calendar->event()->condition('timestamp', strtotime($eventDate[0],$arrayDate[1],$arrayDate[2]))->title($eventTitle)->output('<a href=$eventLink target="newWin">[$eventDate[3]+': '+$eventTitle</a><br />$eventDesc');

I couldnt find out the syntax to run something like above. In the original example.php file, it is:

$event1 = $calendar->event()->condition('timestamp', strtotime(date('F').' 21, '.date('Y')))->title('Hello All')->output('<a href="http://google.com">Going to Google</a><br />Description is here.');

I appreciate if someone helps me to learn this.

Thanks!

图片转代码服务由CSDN问答提供 功能建议

很抱歉提出这个问题,但我是非常新的php,我对这个问题很感兴趣。 我使用代码部分来读取txt文件,如下所示:

我想在php中读取一个txt文件,并使用来自文本的信息创建一个事件。

events.txt包括:

  SEPTEMBER-21-2015-10am 
Google Event 
http://www.google.com  
非常有趣
 
 ... 
 
 $ fh = fopen('events.txt','r'); 
 $ counter = 0; 
while($ line = fgets($ fh)  ){
 if($ counter%4 == 0)
 {
 $ eventDate = explode(“ - ”,$ line); 
} 
 if($ counter%4 == 1)
 {  
 $ eventTitle = $ line; 
} 
 if($ counter%4 == 2)
 {
 $ eventLink = $ line; 
} 
 if($ counter%4 == 3)\  n {
 $ eventDesc = $ line; 
} 
 + $ $ counter; 
} 
 nclclose($ fh); 
   
 
 

我能够 读取我的文件并将我的数据分配给相关变量。 但是,我想使用它们来创建$ event1,如:

  $ event1 = $ calendar-&gt; event() - &gt; condition('timestamp',strtotime(  $ eventDate [0],$ arrayDate [1],$ arrayDate [2])) - &gt; title($ eventTitle) - &gt; output('&lt; a href = $ eventLink target =“newWin”&gt; [$ eventDate  [3] +':'+ $ eventTitle&lt; / a&gt;&lt; br /&gt; $ eventDesc'); 
   
 
 

我无法找到要运行的语法 像上面的东西。 在原始的example.php文件中,它是:

  $ event1 = $ calendar-&gt; event() - &gt; condition('timestamp',strtotime(date('  F')。'21,'。日期('Y'))) - &gt;标题('Hello All') - &gt;输出('&lt; a href =“http://google.com”&gt; Going 到谷歌&lt; / a&gt;&lt; br /&gt;说明就在这里。'); 
   
 
 

如果有人帮我学习,我感激不尽。

谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dozan0001
    dozan0001 2015-09-23 19:53
    已采纳

    If you want evalute runtime the $eventLink and $eventDat[..] variable you must enclose your <a ...> within " (double quote) and not ' (single quote)

    this way :

     "<a href=$eventLink target='newWin'>[$eventDate[3]+": "+$eventTitle</a><br />$eventDesc"
    

    because in PHP the value in single quote are display as is while the value in double quote is evaluate runtime

    点赞 评论

相关推荐