emporio emporio - 1 year ago 96
PHP Question

Converting a DOM element into a string in PHP

I am running a Wordpress site and using WPML translation plugin. In WPML there is a method called

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
, 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>



Answer Source

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()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download