I'm constructing an array in PHP to use it in my Javascript code. So I'm looping over all the posts (Wordpress) and push all the values to a string - which is the Javascript array:
<?php while ( $loop->have_posts() ) : $loop->the_post();
$title = get_the_title();
$address = get_field('address');
$phone = get_field('phone');
$shops = $shops . "['".$title."','".$phone."','".$address."'],";
echo $shops; // for testing.
endwhile; wp_reset_query(); ?>
The input of the address is street, number BREAKRULE zip and city. Example:
Sint Pieterskaai 39
8000 Brugge
And that specific breakrule breaks the string to use as an array in Javascript. Here is a screenshot of the HTML output:
As you can see, there is a <br>
after the house number.
I have already tried to replace the $address
variable with this, but without any luck:
$address = str_replace(array("\r", "\n", "<br>"), '', $address);