3v4l.org

run code in 300+ PHP versions simultaneously
<?php $indicator = '<span class="required">*</span>'; echo "** Before **\n"; var_dump( $indicator ); function replace_glyth( $haystack, $replacement ) { return str_replace( '*', $replacement, $haystack ); } // Replacing the asterisk. echo "\n\n** Direct replacement **\n"; var_dump( replace_glyth( $indicator, 'required' ) ); function replace_translatable_glyth( $haystack, $replacement ) { $pattern = '/(<span class="required">)(.*)(<\/span>)/i'; $replacement = sprintf( '${1}%s${3}', $replacement ); $new = preg_replace( $pattern, $replacement, $haystack ); return $new; $pattern = '/<span class="required">(?<glyth>.*)<\/span>/i'; preg_match( $pattern, $haystack, $matches ); var_dump( $matches ); // No glyth found. if ( empty( $matches['glyth' ] ) ) { return $haystack; } return str_replace( $matches['glyth'], $replacement, $haystack ); } // Since the asterisk is translatable ... echo "\n\n** Pattern to adjust for translatable glyth **\n"; var_dump( replace_translatable_glyth( $indicator, '**required**' ) );
Output for git.master, git.master_jit, rfc.property-hooks
** Before ** string(31) "<span class="required">*</span>" ** Direct replacement ** string(38) "<span class="required">required</span>" ** Pattern to adjust for translatable glyth ** string(42) "<span class="required">**required**</span>"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.21 ms | 405 KiB | 5 Q