douzhangjian1505 2016-05-16 02:27
浏览 128
已采纳

在PHP中将DOM元素转换为字符串

I am running a Wordpress site and using WPML translation plugin. In WPML there is a method called icl_link_to_element(2880); that returns and generates the following element in the DOM:

<a href="https://www.someurl.com/es/atencion-al-cliente">Atención al cliente</a>

I want to convert this element to a string so that I can simply return and store the last part of the url atencion-al-cliente, into a unique variable.

What's the best way to get this done?

Answer to the comment below:

Two elements appear in the DOM now.

<a href="https://www.someurl.com/es/atencion-al-cliente">Atención al cliente</a>

and

"NULL
            "
  • 写回答

2条回答 默认 最新

  • dqve65954 2016-05-16 02:49
    关注

    First do the following steps to get that URL

    1. $page = icl_object_id(2880, 'page', true);
    2. $url = get_permalink($page);

    Then use $parts = explode("/", $url) function and get the last element of that array, you can use array_pop()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部