gpt4 book ai didi

PHP:斜杠转换为数组时变为 "V"

转载 作者:行者123 更新时间:2023-12-04 01:41:24 25 4
gpt4 key购买 nike

我有这个变量:$link = $rows['link'];,其中包含一个 URL。当我回应这一点时,一切都很好。例如:

https://www.ted.com/talks/margaret_heffernan_why_it_s_time_to_forget_the_pecking_order_at_workhttps://www.ted.com/talks/simon_sinek_why_good_leaders_make_you_feel_safehttps://www.ted.com/talks/regina_hartley_why_the_best_hire_might_not_have_the_perfect_resumehttps://www.ted.com/talks/sheryl_sandberg_why_we_have_too_few_women_leadershttps://www.ted.com/talks/roselinde_torres_what_it_takes_to_be_a_great_leaderhttps://www.ted.com/talks/stanley_mcchrystal#t-319307https://www.ted.com/talks/stanley_mcchrystal#t-319307https://www.ted.com/talks/stanley_mcchrystal#t-319307https://www.ted.com/talks/stanley_mcchrystal#t-319307https://www.ted.com/talks/stanley_mcchrystal#t-319307

然后我想使用以下代码将此 URL 保存在数组中: $result['video'][] = array('id' => $id, 'link' => $link) ;

这里的问题是斜杠变成了“V”。例如:echo json_encode($result); 给我:

{"video":[{"id":"1","link":"https://www.ted.com/talks/margaret_heffernan_why_it_s_time_to_forget_the_pecking_order_at_work"},{"id":"2","link":"https://www.ted.com/talks/simon_sinek_why_good_leaders_make_you_feel_safe"},{"id":"3","link":"https://www.ted.com/talks/regina_hartley_why_the_best_hire_might_not_have_the_perfect_resume"},{"id":"4","link":"https://www.ted.com/talks/sheryl_sandberg_why_we_have_too_few_women_leaders"},{"id":"5","link":"https://www.ted.com/talks/roselinde_torres_what_it_takes_to_be_a_great_leader"},{"id":"6","link":"https://www.ted.com/talks/stanley_mcchrystal#t-319307"},{"id":"7","link":"https://www.ted.com/talks/stanley_mcchrystal#t-319307"},{"id":"8","link":"https://www.ted.com/talks/stanley_mcchrystal#t-319307"},{"id":"9","link":"https://www.ted.com/talks/stanley_mcchrystal#t-319307"},{"id":"10","link":"https://www.ted.com/talks/stanley_mcchrystal#t-319307"}]}

谁知道为什么会这样?

谢谢!! :)

最佳答案

你可以通过以下方式解决这个问题

json_encode($result, JSON_UNESCAPED_SLASHES);

关于PHP:斜杠转换为数组时变为 "V",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43202730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com