HTML PHP SPAN ?? Span ID to display value based on the url? - html

www.mysite.com/?q=portraits#
I want a span within my menu to display the current section (ie. portraits)
I'm sure this is simple. Your help is much appreciated!

it's been a long time since i've used php, but the the variable you are referring to is what's known as a query string parameter, which is passed as a $_GET array in php. you can access the specific variable by using a string indexer of the array. in your markup:
<span><?php echo $_GET["q"]; ?></span>

You'll probably have to use javascript, if you're not working with PHP or something like that.
How to extract the get-query with javascript is explained here: How can I get query string values in JavaScript?
Then you can fork the result and add/remove content to/from the element you want to manipulate.

Related

Rendering VueJS prop within HTML array

I have an HTML array with data like so:
data-groups='["category_all", "data goes here"]'
I have a prop called "title" which contains the string I need to render in the "data goes here" area. I've tried using v-bind, but then I lose the array which I need to have in order for the original sort feature to work.
I google'd a few different ways to either escape or render quotes, and most refer to v-bind which again, won't work in this instance.
Any help would be appreciated :)
I was using Shuffle.js and for anyone else seeking an answer, it was in the documentation:
https://vestride.github.io/Shuffle/docs/getting-started
Alternatively, you can set the delimiter option to a comma (delimiter: ',') and the data-groups attribute will be split on that character.
Then changing the above line of code to:
:data-groups="item.category.title + ',all'"
works just fine :)

Web scraping without id VBA

I'm trying to scrape a web , some elements were easy to get . But I have a problem with those who have no id like this .
<TABLE class=DisplayMain1 cellSpacing=1 cellPadding=0><TBODY>
<TR class=TitleLabelBig1>
<TD class=Title1 colSpan=100><SPAN style="FONT-FAMILY: arial narrow; FONT-WEIGHT: normal">Tool & </SPAN><BR>PE311934-1-1 </TD></TR></TBODY></TABLE>
i want this ---►PE311934-1-1
i Try with "document.getElementsByClassName" but the vba gave me a error :/..
some tip?
Use Regular Expressions and the XMLHttpRequest object in VBA
I made a AddIn some time ago that does just that:
http://www.analystcave.com/excel-tools/excel-scrape-html-add/
If you just want the source code then here (GetElementByRegex function):
http://www.analystcave.com/excel-scrape-html-element-id/
Now the actual regex will be quite simple:
</SPAN><BR>(.*?)</TD></TR></TBODY></TABLE>
If it captures too much items simply expand the regex.
You don't specify the error and there is not enough HTML to know how many elements there are on the page.
You may have forgotten to use an index with document.getElementsByClassName("Title1"), as it returns a collection
For example, the first item would be: document.getElementsByClassName("Title1")(0)
In the same way, you could use a CSS querySelector such as .Title1
Which says the same thing i.e. select the elements with ClassName "Title1".
For the first instance simply use:
document.querySelector(".Title1")
For a nodeList of all matching
document.querySelectorAll(".Title1")
and then iterate over its length.
You would access the .innerText property of the element, generally, to retrieve the required string.
For the snippet shown, assuming the item is the first .Title1 on the page the CSS selector retrieves the following from your HTML
The resultant string can then be processed for what you want. This method, and regex, are fragile at best considering how easily an updated source page can break these methods.
In your above example, you can use the class name, .Title1, and then use Replace() to remove the Tool & .

What the difference between 2 name of input?

What the difference between 2 name of input ?
OK, Normal i usually use this format name="xxxxxx"
<input type="text" name="xxxxxx"/>
But, today i see name format that i not understand name="xxxxx[]"
<input type="text" name="xxxxxx[]"/>
what is [] in name="xxxxx[]"
With this format xxxxx[] the variable $_POST['xxxxx'] is an Array when form is posted.
For example, is possible to iterate by the $_POST['xxxxx']:
<?php
$data = filter_input(INPUT_POST, 'xxxxx');
if(is_array($data)) {
foreach($data as $value) {
echo $value;
}
}
?>
In HTML5, the name attribute is just a string (without any special syntax). The only thing that can have a special meaning are the _charset_ and isindex strings. Thus square brackets themselves are nothing special.
However, the authors of programming languages or libraries that interact with HTML forms some times decide to define special syntaxes. That's the case of the PHP server-side language, where paired brackets in form element names are used by the language to automatically define variables of array type. See How do I create arrays in a HTML ? for further details.
(It's possible that other langs make use of similar conventions but I don't really know.)
Nothing, it just another name, may be something auto generated or someone use for a purpose in mind.
This is mainly done because of server side frameworks.
With PHP, for instance, if you had
<input type="text" name="address[firstline]">
and
<input type="text" name="address[secondline]">
and submitted the form, in your PHP code on the server you'd retrieve a single address object from the request and it would have the keys firstline and secondline on it.
you can still query using jQuery:
$('input[address\\[\\]=firstline]')
The reason for needing two backslashes is because a single backslash is interpreted as a JavaScript string escape character, so you need two to specify a literal backslash, which provides the escape character to the selector...

Good way to store formatted text in DB to output later

I write news for my website and format it like this:
[h1]News[h1]
[red]Happy New Year[/red]
[white]Happy New Year[/white]
The news are stored as is on the MySQL DB.
Then when it's called by my website, a function converts every code into HTML format.
[h1][/h1] = <h1></h1>
[red][/red] = <font color=red></font>
I'm not happy with this method for a long time, but now such codes are obsolet for HTML5.
Instead of using I should add it to CSS.
I'm very beginner with PHP, MySQL, CSS, HTML...really, but I'm trying and learning.
So, what I need is the best solution for this matter.
I was thinking to create a CSS rule like:
span.news-red { color=red }
span.news-white { color=white }
And then them into the code for red text, etc...
Is this an effective solution or just a palliative?
Thank you.
EDIT
I have this two functions to convert format of my text in order to be outputed for the visitor.
1st = Converts [white-text][/white-text] into
$string = preg_replace("/\[white-text\](\S+?)\[\/white-text\]/si","<font color=white>\\1</font>", $string);
2nd - Converts [url][/url] into
$string = preg_replace("/\[url\](\S+?)\[\/url\]/si","\\1", $string);
Problems:
WHITE-TEXT - It only changes the color of one word phrases.
URL - It works fine, but I would like to be able to write anything in the readable part of the URL.
In general, you want to have styles of text that are common. Give them descriptions as to why you are doing what you are doing. If I were you, I would name them something as to what they are in the db. Then let's say you decide that Red is just a horrible choice of colors. You could always change it to a different one very easily, just by editing the CSS.
Not knowing why you choose to make something red, I can't give you much of an answer, other than to try and use the css name that relates to why you chose red, rather than what you are doing in the first place.

How to define a variable with random values in Smarty

I need to assign a variable which will be used to create the id label for some html elements.
And it needs to be unique.
I tried
{assign var=unique_id value=`10|mt_rand:20`}
and
{math equation='rand(10,100)'}
But I don't know how to use the result
I don't have any other ideas
this is how you set and use a random value but that deoesn't mean it will be unique.
{assign var=unique_id value=10|mt_rand:20}
{$unique_id}
can you describe a bigger picture of what your doing ?
I wrote an little Smarty plugin some years ago: https://www.markus.zierhut.name/2010/05/21/php-mit-smarty-zufallszahl-erzeugen/
It's a bit easier to use than handling with mt_rand inside the assign-function. And it keeps compatible with the split of Model and View.