Skip to main content
Commonmark migration
Source Link

#Twig, 105 bytes

Twig, 105 bytes

This uses a simple replacement to fill in the gaps.

Twig's replace() filter allows you to define the values to replace as the keys of an hash. Luckly, it also works with arrays, as they have numerical keys.

{{"0a1.
A1 0.
If 0 a1,
Where's the1 0?"|replace(["Peter Piper picked"," peck of pickled peppers"])|raw}}

The |raw is needed to avoid escaping, which turned Where's into Where's.

You can try it on https://twigfiddle.com/phqpts


Since this is compiled down to PHP, the equivalent for PHP would be:

<?php
    $array = array("Peter Piper picked", " peck of pickled peppers");
    $string = "0 a1.
A1 0.
If 0 a1,
Where's the1 0?";
    
    echo str_replace(array_keys($array), $array, $string);

Which can be shortened significatively.

#Twig, 105 bytes

This uses a simple replacement to fill in the gaps.

Twig's replace() filter allows you to define the values to replace as the keys of an hash. Luckly, it also works with arrays, as they have numerical keys.

{{"0a1.
A1 0.
If 0 a1,
Where's the1 0?"|replace(["Peter Piper picked"," peck of pickled peppers"])|raw}}

The |raw is needed to avoid escaping, which turned Where's into Where&#039;s.

You can try it on https://twigfiddle.com/phqpts


Since this is compiled down to PHP, the equivalent for PHP would be:

<?php
    $array = array("Peter Piper picked", " peck of pickled peppers");
    $string = "0 a1.
A1 0.
If 0 a1,
Where's the1 0?";
    
    echo str_replace(array_keys($array), $array, $string);

Which can be shortened significatively.

Twig, 105 bytes

This uses a simple replacement to fill in the gaps.

Twig's replace() filter allows you to define the values to replace as the keys of an hash. Luckly, it also works with arrays, as they have numerical keys.

{{"0a1.
A1 0.
If 0 a1,
Where's the1 0?"|replace(["Peter Piper picked"," peck of pickled peppers"])|raw}}

The |raw is needed to avoid escaping, which turned Where's into Where&#039;s.

You can try it on https://twigfiddle.com/phqpts


Since this is compiled down to PHP, the equivalent for PHP would be:

<?php
    $array = array("Peter Piper picked", " peck of pickled peppers");
    $string = "0 a1.
A1 0.
If 0 a1,
Where's the1 0?";
    
    echo str_replace(array_keys($array), $array, $string);

Which can be shortened significatively.

Source Link
Ismael Miguel
  • 7.9k
  • 2
  • 25
  • 38

#Twig, 105 bytes

This uses a simple replacement to fill in the gaps.

Twig's replace() filter allows you to define the values to replace as the keys of an hash. Luckly, it also works with arrays, as they have numerical keys.

{{"0a1.
A1 0.
If 0 a1,
Where's the1 0?"|replace(["Peter Piper picked"," peck of pickled peppers"])|raw}}

The |raw is needed to avoid escaping, which turned Where's into Where&#039;s.

You can try it on https://twigfiddle.com/phqpts


Since this is compiled down to PHP, the equivalent for PHP would be:

<?php
    $array = array("Peter Piper picked", " peck of pickled peppers");
    $string = "0 a1.
A1 0.
If 0 a1,
Where's the1 0?";
    
    echo str_replace(array_keys($array), $array, $string);

Which can be shortened significatively.