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

  • Home
  • SEARCH
  • 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 8462301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:07:43+00:00 2026-06-10T14:07:43+00:00

With the following string: $string=’some text <photo id=id# /> some text’; Make a substr

  • 0

With the following string:

$string='some text <photo id="id#" /> some text';

Make a substr that if the end of its string is a part of

<photo id="id#" />

then apply an extra chunk to complete

"<photo id="id#" />"

Example:

substr($string,0,15);

result is:

some text <phot

If this happens I need to end up with:

some text <photo id="id#" />

He, can’t find the way of doing this. by the way id# is a random numeric value whose length won’t exceed 3 chars. If regex is necessary to come up with a function.

  • 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-06-10T14:07:45+00:00Added an answer on June 10, 2026 at 2:07 pm

    See this:-

    output:-

    enter image description here

    <?php
    
    $str= 'some text <photo id="#xx"/> some test';
    $parts = preg_split('~(</?[\w][^>]*>)~', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    echo '<pre>';
    print_r($parts);
    echo htmlentities($parts[1]);
    
    
    $str_new= 'some text <photo id="#xx"></photo> some test';
    $parts_new = preg_split('~(</?[\w][^>]*>)~', $str_new, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    echo '<pre>';
    print_r($parts_new);
    echo htmlentities($parts_new[1]);
    echo htmlentities($parts_new[2]);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have following string: var s = '<span>Some Text</span> Some other Text'; The
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
I have the following String that I need to parse. I am looking for
I have the following string format: [[TEXT|TEXT]] <-- the |TEXT is optional And so
Following String causes PatternSyntaxException : Pattern.compile(*\\.*); I want to create a pattern so that
Given the following string http://thedude.com/05/simons-cat-and-frog-100x100.jpg I would like to use substr or trim (or
I have the following string. Input -------------- 2030031469-NAI To get the numeric part, I
Consider the following string: ab(cd.xz) e(ab(fg).xz)) ab(hi.xz) I want to match every substring that
I have following string String str = replace :) :) with some other string;
Imagine I have the following string : set(SEXY_STRING I love CMake) then I want

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.