doubo1871 2015-06-18 19:58
浏览 109

通过PHP将纯文本地址转换为谷歌地图的可点击链接

Pulling in data from a Filemaker Pro database field and trying to convert the plain text data from the field into a clickable link to google maps via PHP.

My first attempt doesnt display anything when called:

$Venue = '<a href="https://maps.google.com/maps?q='.nl2br($record->getField ( 'Auctions::AIS_Venue' )).'"></a>';

$Venue is then echoed into a UL via

<?php echo $Venue; ?>

I'm relatively new to PHP so I'm sure there is a much more semantic way of marking this up? Possibly a regex and replace, returning a preg_replace? Which is what I've been using for plain text URLs and email addresses.

Anything helps, thanks so much.

  • 写回答

1条回答 默认 最新

  • dot_0620 2015-06-20 14:39
    关注

    Casey - not sure there's enough context here to help you? For instance, forget the link wrapping, does

    <?php echo $record->getField( 'Auctions::AIS_Venue'); ?>
    

    actually echo the field contents to a page?

    Also, not sure you really want to use nl2br anyway, as you probably don't want a break in your url ;-)


    OK, in which case there are a couple of things to try. First - can you get it to run in a webviewer inside FileMaker? I suspect not, and it may be down to an encoding/filtering issue.

    There are two approaches you could use.

    1. Create a new calc field in FileMaker that filters out punctuation and converts spaces to '+'s, something like:

      Filter( Substitute( Lower( Auctions::AIS_Venue ) ; [ ¶ ; "+"] ; [" " ; "+"]; ["++" ; "+"]  ); "abcdefghijklmnopqrstuvwxyz1234567890+" )
      

    and then use that field as in your PHP code, or;

    1. Do the same calculation on the fly in PHP, something like:

      $Venue = '<a href="https://maps.google.com/maps?q='.preg_replace( array("/[
       ]+/",'/[^a-zA-Z0-9+]/'), array('+',''), $record->getField ( 'Auctions::AIS_Venue' ) ).'"></a>';
      

    That should do the trick ? ;-)

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c