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

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

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器