I know I might be asking for to much here, but this kind of php-programming isn’t really my thing, so hopefully some of you incredible people can help me with this:
My pagetitle is like this: <em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve
What I need is a snippet that can take out the <em> and </em> out of that pagetitle. That’s the easy part, I hope. It’s like taking out the HTML-tags.
The next thing is a litle more tricky:
I need another snippet that can get <em>Betula nana</em> ssp. <em>tundrarum</em> out of <em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve
or
<em>Euphrasia wettsteinii</em> out of <em>Euphrasia wettsteinii</em> G.Gussarova
****************************
Summary:
First snippet:
<em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve becomes Betula nana L. ssp. tundrarum (Perfil.) Á.Löve & D.Löve
or
<em>Papaver dahlianum</em> Nordh. becomes Papaver dahlianum Nordh.
Second snippet:
<em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve becomes <em>Betula nana</em> ssp. <em>tundrarum</em>
or
<em>Euphrasia wettsteinii</em> G.Gussarova becomes <em>Euphrasia wettsteinii</em>.
Please. And thanks.
I think, thererfor I am! But what I am, and why...?
Maybe I’m misunderstanding your question, but It might be easier to just put the stuff you want in one of the other fields of the document (e.g. Longtitle or Summary). That way you wouldn’t need custom code to extract it. It should execute a little faster as well.
Bob
Thanks for your answer. Yeas I know it would be easier, but I need those fields for other things. And TVs doesn’t work in these case.
I think, thererfor I am! But what I am, and why...?
I solved the first part, where I wanted to take away the HTML-tags in the pagetitle. It was as easy as i hoped:
<?php
$text = $modx->documentObject[’pagetitle’];
echo strip_tags($text);
?>
The next problem is still a bit tricky.
I think, thererfor I am! But what I am, and why...?
Where are these strings coming from:
Quote from: Sylvaticus at Sep 07, 2007, 04:47 PM
The next thing is a litle more tricky:
I need another snippet that can get <em>Betula nana</em> ssp. <em>tundrarum</em> out of <em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve
or
<em>Euphrasia wettsteinii</em> out of <em>Euphrasia wettsteinii</em> G.Gussarova
Depending on where it is coming from you have a couple of options. If it is in your page title and will always come in the order you specified, you can try this:
$pagetitle = $modx->documentObject['pagetitle'];
$string1 = "<em>Betula nana</em> L. ssp. <em>tundrarum</em> (Perfil.) Á.Löve & D.Löve"
$string2 = "<em>Euphrasia wettsteinii</em> G.Gussarova"
if($pagetitle == $string1) {
return substr($string1,0,20);
}
else if ($pagetitle == $string2) {
return substr($string2,0,30);
}
else {
return $pagetitle;
}
Hope that is what you are looking for. If not, just ask again and I will try to help.
Jesse R.
Consider trying something new and extraordinary.
Illinois Wine
Have you considered donating to MODx lately?
Donate now. Every contribution helps.
I made a solution. Don’t know if it’s the best according to good programming, but it works.
The problem now is to call this snippet from a Ditto-template-chunk.
<?php
// samples of pagetitle:
// <em>Genus species</em> Author1 ssp. </em>subspeciesname</em> Author2
// like this:
// <em>Papaver dahlianum</em> Nordh.
// <em>Braya glabella</em> Richardson ssp. <em>purpurascens</em> (R.Br.) Cody
$string = $modx->documentObject['pagetitle'];
$first = strpos($string, "</em>"); // returns the position of the first </em>
$firstPart = substr($string, 0, $first+5); // returns the </em>Genus species</em>
if (preg_match("/\bssp\b/i", $string)) { // if ssp exists
$last = strrpos($string, "</em>"); // returns the position of the last </em>
$second = strpos($string, "ssp."); // returns the position of ssp
$rest = substr($string, 0, $last+5); // returns <em>Genus species</em> Author1 ssp. </em>subspeciesname</em>
$secondPart = substr($rest, $second); // returns ssp. </em>subspeciesname</em>
$newTitle = $firstPart." ".$secondPart;
echo $newTitle; // returns <em>Genus species</em> ssp. </em>subspeciesname</em>
} else {
echo $firstPart; // returns <em>Genus species</em>
}
?>
I think, thererfor I am! But what I am, and why...?