Splitting Smarty PHP Variable Value from CSV into Dropdown/Select

N

NetwiseHosting

Hi All,

A bit of a tricky one for you! This one I'm quite happy to admit is a little over my head, so your thoughts/advice would be much appreciated.

In short, we have a Smarty PHP Variable displaying a value on a web page e.g. {$variable_name} which displays an IP Address in the standard format e.g. 123.456.789.0

This variable can change depending on the client to be a single IP Address, as per the above, or a string of addresses separated by commas e.g. 123.456.789.0, 123.456.789.0, 123.456.789.0

We need to display these addresses in a dropdown/select form list, but I am at a loss on how to manipulate the Smarty PHP output to split into multiple values.

I hope the above makes sense, and thank you in advance for your time guys!
All the best,

Matthew
 
N

NetwiseHosting

Absolutely spot on! Thank you very much, this is the final code I ended up using based on the above in order to populate a dropdown:

PHP:
{assign var=additional_ip_addresses_exploded value=","|explode:$additional_ip_addresses} 
{foreach item=result from=$additional_ip_addresses_exploded name=result} 
	<option value="{$result}">{$result}</option>
{/foreach}

Thanks again for all your help,

Matthew
 
Upvote 0

Latest Articles