Jump to content

get the text between 2 words in a query


anarchoi

Recommended Posts

hi,

I have a query that gets the text of a row in a table and echo it...

The text in the table looks like something like this:

bla bla text bla bla <yo> text text <yo2> bla bla text


Here's what i want to do:
Get the text ONLY between <yo> and <yo2> and put it in a variable
Link to comment
Share on other sites

try[code]<?php
$test ='bla bla text bla bla <yo> 1st texr <yo2> bla bla textbla bla text bla bla <yo> 2nd text <yo2> bla bla textbla bla text bla bla <yo> 3rd text <yo2> bla bla text';
$a = preg_split('/<yo>/',$test);
for ($i = 1; $i < count($a); $i++) {
$b = preg_split('/<yo2>/',$a[$i]);
$c[] = $b[0];
}
print_r($c);
?>[/code]
Link to comment
Share on other sites

[code=php:0]<?php

$string = "bla bla text bla bla <yo>text text<yo2> bla bla text
bla bla text bla bla <yo>some more text<yo2> bla bla text";

preg_match_all('/(?<=<yo>).*?(?=<yo2>)/s', $string, $matches);
$matches = $matches[0];

print_r($matches);

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.