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

在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!

  • 写回答

1条回答 默认 最新

  • 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃