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

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

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条