php - Adding a comma after each category -


this seems pretty straight forward question , reason having trouble figuring out how achieve looking for.

$category = $html2->find('.video_cats',0); $category = $genre->plaintext;   <div class="video_cats"> <span>categories:</span>     <a href="http://www.example.com" title="example category" class="video_cat">house</a>        <a href="http://www.example.com" title="example category" class="video_cat">the cat</a>      <a href="http://www.example.com" title="example category" class="video_cat">car</a>      <a href="http://www.example.com" title="example category" class="video_cat">the dog</a>                                                              </div> 

currently have string called $category if print results of string return following text one 2 3 4 five trying make returns text one, two, three, four, five. appreciated.

edit : desired output category: cat, dog, horse, house because of category names have spaces in them can't replace spaces commas.

search anchors rather div, can loop on them , make array.

$cat_array = array(): foreach ($html2->find(".video_cat") $cat) {     $cat_array[] = $cat->plaintext; }  $category = implode(', ', $cat_array); 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -