I need to remove the last comma of a list of actors in order to parse Google JSON Data Structural Test, i tried several methods with no result, only the last comma has to be removed from output to get no errors from Google. This is the code:
$urls_actors = amy_movie_get_movie_taxomony3( $post->ID, 'amy_actor' );
$urls_actors = explode("," ,$urls_actors);
$actors_name = amy_movie_get_movie_taxomony2( $post->ID, 'amy_actor' );
$actors_name = explode("," ,$actors_name);
foreach ($actors_name as $key => $actor) {
$actors .= '
{
"@type": "Person",
"name": "'.$actor.'",
"url": "'.$urls_actors[$key].'",
"sameAs": "'.$urls_actors[$key].'"
},
';
}
<script type="application/ld+json">
"actor": [
<?php echo $actors;?>],
</script>
And this is the output with the actors list in the script:
"actor": [
{
"@type": "Person",
"name": "Apesanahkwat",
"url": "",
"sameAs": ""
},
{
"@type": "Person",
"name": " Carol Pounder",
"url": "",
"sameAs": ""
},
{
"@type": "Person",
"name": " Christine Kaufmann",
"url": "",
"sameAs": ""
},
{
"@type": "Person",
"name": " Darron Flagg",
"url": "",
"sameAs": ""
},
{
"@type": "Person",
"name": " G. Smokey Campbell",
"url": "",
"sameAs": ""
}, //I need to remove this comma!
],
Thanks for helping out!