I have an input for search ,
i search for "res"
<input type="text" name="search"I/>
i use Like method to get search results,
$txt = $this -> input -> post("search");
$this -> db -> like('title', $txt);
if ($sql = $this -> db -> get('ads') -> result()) {
$data['posts'] = $sql;
print_r($sql);
}
and get this results :
some text restaurant and other
some text result
my resume
i want to show the liked word
extract the word from strings and remove other texts
i want this :
restaurant
result
resume
You can split the found string into an array (explode) and then search this array with the given string (preg_grep) and output the found strings.
<?php
$searchString = "/res/";
$foundString = "some text restaurant and other";
$explode = explode(" ", $foundString);
$searched = preg_grep($searchString, $explode);
foreach($searched as $item) {
echo $item . " ";
}
Related
I am trying to show/hide form fields in a Squarespace form based upon the value selected in a dropdown menu. The dropdown menu has a list of values from 1-10. The intent is to display 2 form fields for each number selected from the dropdown menu. For value 1, I want the form fields titled "Serial Number" and "Confirm Serial Number" to ALWAYS be displayed. For value 2, I want to show "Serial Number 2" and "Confirm Serial Number 2". And so on for values 3-10.
Here is a screenshot of the form as it is now with everything displayed.
enter image description here
You can get the serial element with document.getElementById(`serial-input-${index}`)
You can get the serial confirm element with document.getElementById(`serial-input-confirm-${index}`)
<p>Number of products</p>
<select id="select" onChange="create.input()"></select>
<div id="input"></div>
const create = {
select: () => {
let select = document.getElementById('select')
// Create 1-10 number of products
new Array(10).fill(0).forEach((x, i) => {
let option = document.createElement('option')
option.innerHTML = (i+1)
option.value = (i+1)
select.appendChild(option)
})
},
input: () => {
let input = document.getElementById('input')
let select = document.getElementById('select')
console.log(select.value)
// Remove all child
input.innerHTML = ''
// Create the same number of input has you select in select ...
const size = parseInt(select.value, 10)
new Array(size).fill(0).forEach((x, i) => {
console.log(i)
let p_input = create.p_input(i)
p_input.forEach(x => input.appendChild(x))
})
},
p_input: index => {
let name = `erial number` + (index > 0 ? ' ' + (index+1) : '')
let serial_p = document.createElement('p')
serial_p.innerHTML = 'S' + name
serial_p.id = 'p-serial-' + index
serial_p.class = 'p-serial'
let serial_p_confirm = document.createElement('p')
serial_p_confirm.innerHTML = 'Confirm s' + name
serial_p_confirm.id = 'pc-serial-' + index
serial_p_confirm.class = 'pc-serial'
let serial_input = document.createElement('input')
serial_input.type = "text"
serial_input.id = "serial-input-" + index
serial_input.class = 'serial-input'
let serial_input_confirm = document.createElement('input')
serial_input_confirm.type = "text"
serial_input_confirm.id = "serial-input-confirm-" + index
serial_input_confirm.class = 'serial-input'
return [serial_p, serial_input, serial_p_confirm, serial_input_confirm]
}
}
create.select()
create.input()
for exemple here its what i get when i click on 5.
I am trying with below code :
public void verifyCategorySlugsInSearchcall(BaseDTO baseDTO, String jsonResponse) {
List<String> categoryList = JsonPath.read(jsonResponse,
"response.groups.DEFAULT_GROUP.documents[*].categorySlugs[*]");
CustomReporter.reportInfoWithOutLineBreak("Category from search call Response:" + categoryList);
Assert.assertTrue(categoryList.size() > 0, "No category slug name was displayed.");
CustomReporter.reportInfoWithOutLineBreak("Category Slug from search call Response:" + categoryList);
Assert.assertTrue(categoryList.contains(baseDTO.getPsCallDetails().getCategory()),
"Category Name was not matching. Actual:" + categoryList + ".Expected:"
+ baseDTO.getPsCallDetails().getCategory());
}
My arrayalist contains all category name :
eg: ["apple-tv-apple-tv-4k","apple-tv-apple-tv-4k","apple-tv-apple-tv"]
Need to search apple-tv contains in this array. My code is giving error as not contains apple-tv in particular category.
Using streams:
boolean result = categoryList.stream()
.anyMatch(c -> c.contains("apple-tv"));
If you instead want to generate a new list containing only categories having apple-tv somewhere in the name, then use filter:
List<String> output = categoryList.stream()
.filter(c -> c.contains("apple-tv"))
.collect(Collectors.toList());
Currently I have multiple dropdown field in screen. when selected dropdown value pass in the query param so I want to create dynamic query param added. my code is below
// this is one of the dropdown value
if (this.SearchText) {
query += 'q:' + SearchText + ',';
}
// this is the second one of dropdown value
if (this.MakeId) {
makename = this.SpaceToDash(this.MakesList.find(x => x.Id === +this.MakeId).Name);
navigateUrl += '/' + makename;
query += 'merk:' + this.MakeId + ',merkname:' + makename + ',';
}
this.router.navigate([ navigateUrl ], { queryParams: { query } });
So if "MakeId" is not dropdown value then should not added in "queryParams" so how can I do it. Above solution is not working it.
Apply solution for Dynamically create query Params in Angular 2 but it is not fit in my requirement. So can you help me anyone in it?
QueryParams should take an Object not a string ,
so you can do it by this way
let query = {};
// this is one of the dropdown value
if (this.SearchText) {
query['q'] = SearchText;
}
// this is the second one of dropdown value
if (this.MakeId) {
makename = this.SpaceToDash(this.MakesList.find(x => x.Id === +this.MakeId).Name);
navigateUrl += '/' + makename;
query['merk'] = this.MakeId;
query['makename'] = makename;
}
this.router.navigate([ navigateUrl ], { queryParams: query });
I have scriptet me a maps with markers based on a MySQL Table.
The position is in the Table.
Now, i would like to write with HTML in the InfoWindow, because it not show HTML on the InfoWindow on the Map.
downloadUrl('inc/map_bridge.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var ide = markerElem.getAttribute('id');
var desc = markerElem.getAttribute('beschreibung');
var type = markerElem.getAttribute('art');
var link = '<p>Klicke für weitere infos: Hier';
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = 'ID' + ide + ': ' + name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
text.textContent = desc + link
infowincontent.appendChild(text);
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
label: icon.label
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}
It show only so:
show example picture
the following i have in the MySQL-Table
first line<br>second line
If 'beschreibung' were the result of SELECT SQL, the reason is escaped SELECT
SQL result.
(I'm in short of reputation, so write in answer form.)
I have some roles and each roles have users.
So my problem is according to the no. of roles and no. of users selected i have to create a graph using graphviz.
Graphviz language is like (A -> B;)(B -> C;)(B -> D;)(C -> E;)(D -> E;)(E -> F)
So i have to create a graph language according to no of roles i have and no. of users i selected...
The incoming string is like = (1CS_3Admin_1BOD_2SH_1Others).
And the graph for this language myst be like this:-
marapet This is what i am doing.
My language is like 1CS_3Admin_1BOD_2SH_1Others Where 1,3,1,2 is the no of users selected e.g 1CS means one user for CS role. Now i split them with '_' as delimiter . Now i get a string array . So the real problem is to make a language from this string array values.
Here 'name' is the string i am getting:-
Graphviz gv = new Graphviz();
gv.addln(gv.start_graph());
gv.addln("Start;");
if(name.startsWith("_"));
name=name.substring(1);
String[] str=null;
if(name.contains("_"))
str = name.split("_");
int sPreviousRepeat=0;
String sPrevious="";
int sCurrRepeat=0;
String sCurr="";
String finalInst="Start -> ";
for(int i=0;i<str.length;i++) {
sCurrRepeat=Integer.parseInt(String.valueOf(str[i].charAt(0)));
sCurr=str[i].substring(1);
if(i!=0){
sPreviousRepeat = Integer.parseInt(String.valueOf(str[i-1].charAt(0)));
sPrevious = str[i-1].substring(1);
}
if(sCurrRepeat==1){
if(i==0)
finalInst=finalInst+sCurr+";";
else
finalInst=finalInst + sPrevious+" -> "+sCurr+";";
}
else{
for(int j=0;j<sCurrRepeat;j++){
//cant figure out?????
}
}
}
Here's how I'd break down the problem:
Parse the input string into a data structure representing n ordered pairs of role and number of users
Creating the syntax of the graph (graphviz dot) from the data structure in #1
Transform the graphviz syntax into an actual image
You'll need to learn the following:
Graphviz syntax
Making a simple Java command line program
Parsing and manipulating strings in Java (split etc.)
Invoking an executable from java (dot.exe)
I think i make it.
if(name.contains("_"))
str = name.split("_");
int sPreviousRepeat=0;
String sPrevious="";
int sCurrRepeat=0;
String sCurr="";
String finalInst="Start -> ";
for(int i=0;i<str.length;i++) {
sCurrRepeat=Integer.parseInt(String.valueOf(str[i].charAt(0)));
sCurr=str[i].substring(1);
if(i!=0){
sPreviousRepeat = Integer.parseInt(String.valueOf(str[i-1].charAt(0)));
sPrevious = str[i-1].substring(1);
}
if(sCurrRepeat==1){
if(i==0)
finalInst=finalInst+sCurr+";";
else if(sPreviousRepeat>1){
for(int j=0;j<sPreviousRepeat;j++)
finalInst=finalInst + sPrevious+(j+1)+" -> "+sCurr+";";
}
else
finalInst=finalInst + sPrevious+" -> "+sCurr+";";
}
else{
for(int j=0;j<sCurrRepeat;j++){
finalInst=finalInst + sPrevious+" -> "+sCurr+(j+1)+";";
}
}
}