Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:38:50+00:00 2026-05-28T05:38:50+00:00

Here is the problem : I want to split a string to have the

  • 0

Here is the problem : I want to split a string to have the name and the first name, but my two variable are empty and i don’t understant why… Can someone help me ? This my code :

 $nom_aut1 = "";
 $prenom_aut2 = "";
 //$auteur1 is already initialized

  for ($i = 0; $i < strlen($auteur1); ++$i)
  {
    if ($auteur1[$i] != ' ') continue;

    for ($j = 0; $j < $i; ++$j)
    {
      $nom_aut1 .= $auteur[$j];
    }

    for ($j = $i+1; $j < strlen($auteur1); ++$j)
    {
      $nom_aut1 .= $auteur1[$j];
    }

    break;
  }
  echo '"'.$nom_aut1.'.'.$prenom_aut1.'"';

Thank you 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:38:51+00:00Added an answer on May 28, 2026 at 5:38 am

    Do you want to split a name into first and last name based on a space? Why not just do this:

    $names = explode(" ",$name);
    

    If $name = "Hello World"

    $names will be an array such that

    $names[0] = "Hello"
    $names[1] = "World" 
    

    This way, if there is a middle name, you can get that as well.

    You can do it this way:

    $names = explode(" ",$name);
    
    if (count($names) == 1) //only first name
    {
        $first = $names[0];
        $last = "";
    }
    else if (count($names) == 2) //only first and last name
    {
        $first = $names[0];
        $last = $names[1];
    }
    else    //one or more middle names were provided
    {
        $first = $names[0];
        $last = $names[count($names)-1];
    
        for($i=1;$i<count($names)-1;$i++)
            $middle .= $names[$i] . ' ';
        $middle = trim($middle);  
    }
    

    So, if $name = "Hello Foo Bar World"

    $first = "Hello"
    $last = "World"
    $middle = "Foo Bar"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here is my problem. I want to redirect name.domain.com/trips/1 to domain.com?username=name&trip=1 using modrewrite.
I have a string with two different delimiters (| and ~). I want to
I want to JOIN two table. Have no problem with that. I have problem
here is my Problem, I want to pass the integer 1 when this canvas
So here is my problem. I want to store 2-tuple (key, val) and want
I have a problem here. My Zend_Forms do not render in view script. Via
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
further to my previous question , I have a new problem now, I want
Hi here is my problem. I have a program that calulcates the averages of
I have a pretty simple general programming problem, yet I can't quite get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.