I have a piece of code and XPath to export it. the code is:
<div class="container-fluid">
<ul class="tags expandable">
<li><a class="search__link" href="domain.com">office</a></li>
<li><a class="search__link" href="domain.com">space</a></li>
</ul>
</div>
and the Xpath is :
//ul[contains(concat (" ", normalize-space(#class), " "), " tags expandable ")]
this Xpath export data is like this: "office space"
but I want to insert "," after each li and I want the export like this: "office, space,"
You should use something like this with XPath 1.0:
translate(normalize-space(//ul)," ",",")
returns "office,space".
To add the last coma :
concat(translate(normalize-space(//ul)," ",","),",")
returns "office,space,".
EDIT : With the website link you posted, use this one-liner to get what you want :
translate(normalize-space(//div[#class="container-fluid"]/ul)," ",",")
Output :
People,Space,Women,Friends,Communication,Group,Support,Community,Beautiful,Unity,Gender,Movement,Gathering,Copy,Rights,Feminist,Empower,Supporting,Copy,space,Empowering
It still needs some corrections (remove the undesired "," between Copy and space). If you need something fully automatic and since you have to use XPath 1.0 (no replace function), you can try :
translate(normalize-space(translate(//div[#class="container-fluid"]/ul," ",""))," ",",")
Output (Copy space are now merged) :
People,Space,Women,Friends,Communication,Group,Support,Community,Beautiful,Unity,Gender,Movement,Gathering,Copy,Rights,Feminist,Empower,Supporting,Copyspace,Empowering
Otherwise, just use :
//ul[#class="tags expandable"]//a/text()
And add the comas with the programming language you want.
So basically i have an input type text which is validated to contain only numbers, comma and dot. When i enter(5.32) for example everything is okay but when i enter (5,32) it won't let me submit it, because it recognizes it as a string, which i don't want. How can i convert the comma into a dot in backend and still show as a comma ?
<input type="text" name="monthly_price" id="monthly_price" value="" class="comma-validation">
$('.comma-validation').on('input', function() {
var currentInput = $(this).val();
var fixedInput = currentInput.replace(/[^0-9 \,.]/, '');
$(this).val(fixedInput);
});
In your controller you can do:
$monthlyPrice = (float)str_replace(',', '.', request('monthly_price'));
This replaces the comma into a decimal. Then casts it as a float.
I encountered a problem that need to write some HTML codes in ternary operator in Thymeleaf. In where I need to chose an anchor link by using ternary operator. For better understand, I putted those problematic code in below:
<span th:text="${error_code == '404'} ? 'Home' : 'Login'"></span>
So, how can I wirte those code correclty in Themeleaf
This should do it :
<span th:utext="((${error_code} == '404') ? '<a href="http://localhost:8080/home">Home</a>' : '<a href="http://localhost:8080/login">Login</a>')"></span>
" is for escaping double quote in html.
utext is to tell thymeleaf not to print plain text as "< a href.. "
For example I want to have all commas (or whatever other characters like this: " /, |, &, $ and so on " ) from a text in different colors.
Is this possible?!
You could use spans to separate the commas or ampersand from the rest of the text
<p> Some text <span style="color:pink">/</span> Some text ....</p>
I don't think is yet possible using only css
In PHP you could theme your text with preg_replace to add the spans around the comma, ampersand, slash, etc.
http://php.net/manual/en/function.preg-replace.php
or str_replace
<?php str_replace(',', '<span class="pink">,</span>', $string); ?>
For wordpress add the suggested code to your template file, for more info about templating see:
http://codex.wordpress.org/Stepping_Into_Templates
This do the thing:
add_filter('the_content', 'testfilter');
function testfilter($content) {
$pattern = ' | '; //search content for ' | ' string
$replacement = '<span class="test">' . $pattern . '</span>'; //replace it with the same term but inside a span
$replaced = str_replace($pattern, $replacement, $content);
return $replaced;
}
Credits goes here: *http://wordpress.org/support/topic/str_replace-content-with-a-span-class*
The string
<div id="main">
content (is INT)
<div>some more content (is not INT) other content (also INT)</div>
</div>
I need to get the content which is an INT. A simple strip all non-INT function will not work since other contentsometimes also is an INT. I cannot use a select child solution since it is always outside div and to select the content of <div id="main">will also select the other div.
Thus is there a solution that can search the string from start for the first <and remove the rest of the string when found.
(The structure cannot be altered)
if that's the exactly format, you could just use substr and strpos
something like
$html = '<div id="main">
12345
<div>foobar6789</div>
</div>
';
$content_1 = substr($html,15,strpos($html,'<div>')-15); //the first INT content
$subdiv = str_replace("</div>","",substr($html,strpos($html,'<div>')+5));
preg_match('/(?P<noint>[^0-9]+)(?P<digit>\d+)/', $subdiv, $matches);
echo $matches['noint'];//the NO INT content
echo $matches['digit'];//the second INT
it's not a good idea to parse html using regexp... but maybe you could do it using only preg_match...
good luck!