Archives Wild Code School
PHP

✏️ Exercise 3 - String manipulation

Quête 11 sur 14

Introduction

image

⚠️ Avant de commencer cette quête, tu dois avoir terminé les quêtes suivantes :
Quêtes liées

💪 Défi

Exercice 1 : le cercle de la vie

Écris ton histoire sur le cercle de la vie, en utilisant les 6 variables ci-dessous. Tu dois utiliser l'opérateur de concaténation (concatenation operator) (l'opérateur qui colle des chaînes de caractères bout à bout).

php
$seedling = '🌱';
$caterpillar = '🐛';
$spider = '🕷️';
$frog = '🐸';
$owl = '🦉';
$fox = '🦊';

// write your story in this variable
$circleOfLife = '';

Exercice 2 : Le roi est mort, vive le roi !

php
$king = 'Mufasa';
  • affiche uniquement le premier caractère du nom $king
  • affiche uniquement le dernier caractère du nom $king
  • Change le nom du roi, c'est désormais 'Simba'.
  • affiche uniquement le deuxième caractère du nouveau nom $king

Exercice 3 : les anagrammes

En utilisant les variables ci-dessous, trouve l'anagramme et concatène les caractères dans le bon ordre pour l'afficher.

Astuce : bien sûr, tu ne dois pas écrire directement la réponse, mais récupérer chaque caractère depuis la variable, les réordonner et utiliser l'opérateur de concaténation.

php
$shinningAnagram = 'star';
// display anagram here 🐀🐀🐀 

$oldAnagram = 'raptor';
// display anagram here 🦜

🧐 Critères d'acceptation

  • [ ] Toutes les strings (chaînes de caractères) sont correctement affichées
  • [ ] Tu as compris l'opérateur de concaténation
  • [ ] Tu sais comment récupérer un caractère précis dans une string

Introduction

image

⚠️ Before starting this quest, you must have finished the following quests:
Quêtes liées

💪 Challenge

Exercice 1 : circle of life

Write your story about the circle of life, using the 6 variables below. You should use the concatenation operator.

php
$seedling = '🌱';
$caterpillar = '🐛';
$spider = '🕷️';
$frog = '🐸';
$owl = '🦉';
$fox = '🦊';

// write your story in this variable
$circleOfLife = '';

Exercice 2 : The king is dead, long live the king!

php
$king = 'Mufasa';
  • display only the first character of the $king name
  • display only the last character of the $king name
  • Change the name of the king, it is now 'Simba'.
  • display only the second character of the new $king name

Exercice 3 : anagrams

Using the variables below, find the anagram and concatenate characters in the correct order to display it.

Hint : of course, you should not directly write the answer, but get each character from the variable, reorder them and use concatenation operator.

php
$shinningAnagram = 'star';
// display anagram here 🐀🐀🐀 

$oldAnagram = 'raptor';
// display anagram here 🦜

🧐 Acceptance criteria

  • [ ] All the strings are correctly displayed
  • [ ] You have understand the concatenation operator
  • [ ] You know how to retrieve a particular character in a string