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 8467291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:36:01+00:00 2026-06-10T15:36:01+00:00

Here is working php code <?php $str = ‘<users> <user id=1 value1=afaaf value2=racad value3=xarcd>User1</user>

  • 0

Here is working php code

<?php
$str = '<users>
<user id="1" value1="afaaf" value2="racad" value3="xarcd">User1</user>
<user id="2" value1="fsvgvdsg" value2="wdafsc" value3="aefvbdfg">User2</user>
<user id="3" value1="chthb" value2="rtvfascf" value3="xasedfvg">User3</user>
</users>';
$out = '';
if(preg_match_all('|<user id="(.*)" value1="(.*)" value2="(.*)" value3="(.*)">(.*)</user>|',$str,$matches))
{
    for($i=0;$i<count($matches[1]);$i++)
    $out .= $matches[1][$i].'|'.$matches[2][$i].'|'.$matches[3][$i].'|'.$matches[4][$i].'|'.$matches[5][$i]."\n";

    echo $out;
}
 ?>

This is what I get

1|afaaf|racad|xarcd|User1
2|fsvgvdsg|wdafsc|aefvbdfg|User2
3|chthb|rtvfascf|xasedfvg|User3

C# code

    string patt = "<user id=\"(.*)\" value1=\"(.*)\" value2=\"(.*)\" value3=\"(.*)\">(.*)</user>";
    string str = "<users><user id=\"1\" value1=\"afaaf\" value2=\"racad\" value3=\"xarcd\">User1</user><user id=\"2\" value1=\"fsvgvdsg\" value2=\"wdafsc\" value3=\"aefvbdfg\">User2</user><user id=\"3\" value1=\"chthb\" value2=\"rtvfascf\" value3=\"xasedfvg\">User3</user></users>";
    MatchCollection mc;
    Regex r = new Regex(patt);
    mc = r.Matches(str);

    for (int i = 0; i < mc.Count; i++)
        textBox1.Text += mc[i].Value + "\r\n";

and I get

<user id=\"1\" value1=\"afaaf\" value2=\"racad\" value3=\"xarcd\">User1</user><user id=\"2\" value1=\"fsvgvdsg\" value2=\"wdafsc\" value3=\"aefvbdfg\">User2</user><user id=\"3\" value1=\"chthb\" value2=\"rtvfascf\" value3=\"xasedfvg\">User3</user>\r\n

You can see that string what i get from c# code isn’t even close to my php result.

How to get result like from my php code?

Hope you understand what is my problem here.

Thanks

  • 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-10T15:36:02+00:00Added an answer on June 10, 2026 at 3:36 pm

    try this :

    change (.*) to (.*?) in you RegEx pattern
    

    and modify your snippet as:

    for (int i = 0; i < mc.Count; i++)
        textBox1.Text += mc[i].Groups[1].Value + mc[i].Groups[2].Value + mc[i].Groups[3].Value + + mc[i].Groups[4].Value + mc[i].Groups[5].Value + "\r\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the php code that I'm working with in my local machine: $m
here is my working php explode code for NON links: <?php $textarea = get_custom_field('my_custom_output');
What I have here is a PHP page working with the Facebook API. What
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir , but I
I thought I'd put the working solution here for others interested in a code
I am working on a PHP code for my social network, what I am
I'm working on translating some php code to Python. I'm not an expert in
PHP developer here working with c#. I'm using a technique to remove a block
While reviewing some PHP code I've discovered a strange thing. Here is the simple

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.