duanliu8998 2016-08-01 09:44
浏览 28
已采纳

当实体中包含Apostrophes时,不能使用array_search()

I'm having an issue where I have a list of company's as an array and I am using array_search() to get the Keys from this array to store in a database as an ID.

This works with all of my company's except ones with apostrophes in them! I don't know how array_search() works specifically but I can't find a solution posted online for this.

<?php
$array = array("pipefix", "Housing ltd","o'briens roofing","argos");
$search = "o'briens roofing";

$id = array_search($search, $array);
print_r($id);

This is obviosuly not my exact code, but is the same principle, I am trying to search the array for my company, but if it has an ' in it, it will always return nothing! Any ideas or solutions for this?

  • 写回答

1条回答 默认 最新

  • dongpang2483 2016-08-03 10:52
    关注

    The Array i used is pulled from another databases stored information and is posted on an API that i have no control over unfortunately.

    I do not store this my my database, I only store the [ID's] for management and inputs.

    The array pulled is HTML encoded when retrieved.

    I pulled this array from the API using JSON and cUrl. This means when i first get hold of the array values the Apostrophe has been converted to &apos;s.

    I thought using htmlsecialchars_decode() would revert this. Thanks to Ryan Vincent he has shown me the issue is created when it is Pulled using cUrl.

    Unfortunately i can not change this so when the array is created, I now do a str_replace() and simply remove the &apos;s.

    This means once displayed it is technically incorrect. but as this is only being used by a few people it is more efficient to do this than have to do it on the back end for every search.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度