There are 3 links, one line, let's call it conditionally "array" -

http://www.russianfood.com/recipes/recipe.php?rid=120590|http://www.gastronom.ru/recipe/14679/makarony-po-flotski|http://webspoon.ru/receipt/makarony-po-flotski 

separated by such a symbol - | Dear gurus, tell me a regular file to get real links from this “array”, just like this:

 www.russianfood.com www.gastronom.ru webspoon.ru 

but, just so that he would display as many end links as there are in the "array".

Sorry, while I myself only understand regular expressions, I learned only this:

 echo str_replace('|', '<br>', $composition); 

Please tell me an example in my sabzh, I will be extremely grateful. Thank!

  • 1) explode() - we explode() into an array of links, 2) parse_url - we get the host name for each element of the array - BOPOH
  • @BOPOH Thanks for trying now! Tell me, is it still necessary for your recipe to output elements in a loop? - Incognito
  • what does "output" mean? to the page? Yes, you first receive the necessary data, then output them, do not mix logic with the display - BOPOH
  • @BOPOH Thank you! Everything worked out! - Incognito

2 answers 2

 $pi_mass = explode('|', (ссыль1|ссыль2|ссыль3)); $pi_count = count($pi_mass); for($j=0;$j<$pi_count;$j++){ ?><a href="<? echo $pi_mass[$j]; ?>"><? echo parse_url($pi_mass[$j], PHP_URL_HOST); ?></a></br><?} 

In my opinion there is not enough brackets?

PS I can not edit the message.

PS [2] Completed the answer by correcting a typo, added a bracket.

Thanks @BOPOH for the tip, mana is a great power !!!

 $pi_mass = explode('|', (ссыль1|ссыль2|ссыль3); $pi_count = count($pi_mass); for($j=0;$j<$pi_count;$j++){ ?><a href="<? echo $pi_mass[$j]; ?>"><? echo parse_url($pi_mass[$j], PHP_URL_HOST); ?></a></br><?} 
  • use foreach($pi_mass as $_mass) so more convenient in $_mass will be the value - Naumov
  • @Naumov Yes, thanks! It really is easier. - Incognito