I need to list a text field with values separated by;

2

I have a text field that is being inserted into the same phones in this format:

11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333

I need to list these fields as if it were a simple select in line and column . the result I need is this:

11 2222-3333
12 9 1111-2222
18 1111-2222
11 2222-3333
    
asked by anonymous 13.06.2014 / 04:26

3 answers

4

You swallow the data in your SQL and put in a variable the part of the phones, in my example it was in $str and I follow the code below:

<?php
   $str = '11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333';
   $strs = explode(';', $str);
   foreach($strs as $st){
      echo $st;
      echo PHP_EOL;
   }

Example: ideone

Obs: do the conversions in PHP, which is the best solution

    
13.06.2014 / 04:56
1

There are several ways to do it, one option would be to make a explode () and then implode () , example:

$str = '11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333';
echo implode('<br/>',explode(';',$str));

Or str_replace ()

$str = '11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333';
echo str_replace(';','<br/>',$str);
    
13.06.2014 / 16:20
0

I would use str_replace:

$str = '11 2222-3333;12 9 1111-2222;18 1111-2222;11 2222-3333';
echo str_replace(';', '<br />', $str);
    
14.06.2014 / 21:44