Jump to content

Recommended Posts

how would I go about detecting the text between two strings. For example.

 

blah blah blah [countdown]12467946446[/countdown] more blah

 

the script would search for anything between [countdown] and [/countdown]

 

then make the output $countdown

 

that way I could do

 

countdown($countdown,false).

 

I have already made the countdown function and know how to only get numbers from the string. I'm just not sure how to find it.

 

Would you do something like find the position of the [countdown] and [/countdown] in the text and then only take that bit?

Link to comment
https://forums.phpfreaks.com/topic/121425-get-text-between-2-string/
Share on other sites

potentially multiples. for example there might be

 

$string = "Woo, [countdown]1230163200[/countdown] until Christmas. That means its [countdown]1230768000[/countdown] until 2009.";

 

And then something like

 

$orig = '#[countdown][^"]*[/countdown]#'; 
$cd = countdown($1);
$rep = $cd['days']." Days, ".$cd['hours']." Hours and ".$cd['minutes']." Minutes. "
$string = preg_replace($orig,$rep,$string); 

I have got this far.

 

while ($row = mysql_fetch_array($query2)){
$entry = $row['Entry'];
$entry = preg_replace('#[countdown][^"]*[/countdown]#',countdown("\\1",false),$entry); //Line 109
echo "<tr>";
echo "<td style='text-align: left'><h3><u><strong>".$row['Name']."</strong></u></h3></td>";
echo "<td style='text-align: right'><i>".date("jS F Y", $row[Date])."</i></td>";
echo "</tr><tr>";
echo "<td colspan='2' style='text-align: left'>".$entry."<hr /><br /></td>";
echo "</tr>";
}

 

 

And get this error.

 

Fatal error: Cannot pass parameter 1 by reference in /home/evo/public_html/madnessred/pages/home.php on line 109

 

<pre>
<?php
$string = "Woo, [countdown]1230163200[/countdown] until Christmas. That means its [countdown]1230768000[/countdown] until 2009.";
function countdown ($in) {
	### Calculations here.
	return $in;
}
echo preg_replace('%\[countdown\](.*?)\[/countdown\]%e', 'countdown("$1")', $string);
?> 
</pre>

firstly what does

<pre>

do?

 

secondly, where the function is, can I just put the include there?

 

<?php
$string = $row['Entry'];
include('countdown.php');
$entry =  preg_replace('%\[countdown\](.*?)\[/countdown\]%e', 'countdown("$1")', $string);
?>

firstly what does

<pre>

do?

 

I use it in all of my examples because it's oftentimes required for printing arrays and such; see http://www.w3schools.com/TAGS/tag_pre.asp. You can disregard.

 

secondly, where the function is, can I just put the include there?

 

Yes.

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.