IHYPRESS.NET
PHP
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
PHP ❯ Strings
<12>
<?php /* working with strings */ $string = "Albuquerque is the largest city in the state of New Mexico."; echo "<div style='font-size:22px;color:#337722;'>"; /* finding characters */ $c = strpos($string, "c"); echo "The first letter 'c' was found at position #$c.<br>"; $c2 = strpos($string, "c", $c + 1); echo "The second letter 'c' was found at position #$c2.<br>"; /* replacing parts of a string */ $new = str_replace("ue", "UE", $string); echo "$new<br>"; /* substring replacements */ $new2 = substr_replace($string, "", 0, 10); $new3 = substr_replace($string, "", -10, 10); echo "$new2<br>"; echo "$new3<br>"; /* string to array */ $parts = explode(" ", $string); echo "The 5th word is <b>$parts[4]</b>.<br>"; /* array to string */ $new4 = implode("_", $parts); echo "$new4<br>"; echo "</div>"; ?>
The first letter 'c' was found at position #27.
The second letter 'c' was found at position #56.
AlbuqUErqUE is the largest city in the state of New Mexico.
e is the largest city in the state of New Mexico.
Albuquerque is the largest city in the state of N
The 5th word is city.
Albuquerque_is_the_largest_city_in_the_state_of_New_Mexico.
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.